3 test_description
='test cherry-picking many commits'
5 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
6 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
8 TEST_PASSES_SANITIZE_LEAK
=true
11 check_head_differs_from
() {
12 test_cmp_rev
! HEAD
"$1"
16 test_cmp_rev HEAD
"$1"
19 test_expect_success setup
'
23 git commit -m "first" &&
26 git checkout -b other &&
27 for val in second third fourth
32 git commit -m "$val" &&
33 git tag $val || return 1
37 test_expect_success
'cherry-pick first..fourth works' '
38 git checkout -f main &&
39 git reset --hard first &&
41 git cherry-pick first..fourth &&
42 git diff --quiet other &&
43 git diff --quiet HEAD other &&
44 check_head_differs_from fourth
47 test_expect_success
'cherry-pick three one two works' '
48 git checkout -f first &&
52 git checkout -f main &&
53 git reset --hard first &&
54 git cherry-pick three one two &&
55 git diff --quiet three &&
56 git diff --quiet HEAD three &&
57 test "$(git log --reverse --format=%s first..)" = "three
62 test_expect_success
'cherry-pick three one two: fails' '
63 git checkout -f main &&
64 git reset --hard first &&
65 test_must_fail git cherry-pick three one two:
68 test_expect_success
'output to keep user entertained during multi-pick' '
69 cat <<-\EOF >expected &&
71 Author: A U Thor <author@example.com>
72 Date: Thu Apr 7 15:14:13 2005 -0700
73 1 file changed, 1 insertion(+)
75 Author: A U Thor <author@example.com>
76 Date: Thu Apr 7 15:15:13 2005 -0700
77 1 file changed, 1 insertion(+)
79 Author: A U Thor <author@example.com>
80 Date: Thu Apr 7 15:16:13 2005 -0700
81 1 file changed, 1 insertion(+)
84 git checkout -f main &&
85 git reset --hard first &&
87 git cherry-pick first..fourth >actual &&
88 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
89 test_line_count -ge 3 actual.fuzzy &&
90 test_cmp expected actual.fuzzy
93 test_expect_success
'cherry-pick --strategy resolve first..fourth works' '
94 git checkout -f main &&
95 git reset --hard first &&
97 git cherry-pick --strategy resolve first..fourth &&
98 git diff --quiet other &&
99 git diff --quiet HEAD other &&
100 check_head_differs_from fourth
103 test_expect_success
'output during multi-pick indicates merge strategy' '
104 cat <<-\EOF >expected &&
107 Author: A U Thor <author@example.com>
108 Date: Thu Apr 7 15:14:13 2005 -0700
109 1 file changed, 1 insertion(+)
112 Author: A U Thor <author@example.com>
113 Date: Thu Apr 7 15:15:13 2005 -0700
114 1 file changed, 1 insertion(+)
117 Author: A U Thor <author@example.com>
118 Date: Thu Apr 7 15:16:13 2005 -0700
119 1 file changed, 1 insertion(+)
122 git checkout -f main &&
123 git reset --hard first &&
125 git cherry-pick --strategy resolve first..fourth >actual &&
126 sed -e "s/$_x05[0-9a-f][0-9a-f]/OBJID/" <actual >actual.fuzzy &&
127 test_cmp expected actual.fuzzy
130 test_expect_success
'cherry-pick --ff first..fourth works' '
131 git checkout -f main &&
132 git reset --hard first &&
134 git cherry-pick --ff first..fourth &&
135 git diff --quiet other &&
136 git diff --quiet HEAD other &&
137 check_head_equals fourth
140 test_expect_success
'cherry-pick -n first..fourth works' '
141 git checkout -f main &&
142 git reset --hard first &&
144 git cherry-pick -n first..fourth &&
145 git diff --quiet other &&
146 git diff --cached --quiet other &&
147 git diff --quiet HEAD first
150 test_expect_success
'revert first..fourth works' '
151 git checkout -f main &&
152 git reset --hard fourth &&
154 git revert first..fourth &&
155 git diff --quiet first &&
156 git diff --cached --quiet first &&
157 git diff --quiet HEAD first
160 test_expect_success
'revert ^first fourth works' '
161 git checkout -f main &&
162 git reset --hard fourth &&
164 git revert ^first fourth &&
165 git diff --quiet first &&
166 git diff --cached --quiet first &&
167 git diff --quiet HEAD first
170 test_expect_success
'revert fourth fourth~1 fourth~2 works' '
171 git checkout -f main &&
172 git reset --hard fourth &&
174 git revert fourth fourth~1 fourth~2 &&
175 git diff --quiet first &&
176 git diff --cached --quiet first &&
177 git diff --quiet HEAD first
180 test_expect_success
'cherry-pick -3 fourth works' '
181 git checkout -f main &&
182 git reset --hard first &&
184 git cherry-pick -3 fourth &&
185 git diff --quiet other &&
186 git diff --quiet HEAD other &&
187 check_head_differs_from fourth
190 test_expect_success
'cherry-pick --stdin works' '
191 git checkout -f main &&
192 git reset --hard first &&
194 git rev-list --reverse first..fourth | git cherry-pick --stdin &&
195 git diff --quiet other &&
196 git diff --quiet HEAD other &&
197 check_head_differs_from fourth