3 test_description
='test cherry-pick and revert with conflicts
6 + picked: rewrites foo to c
7 + base: rewrites foo to b
8 + initial: writes foo as a, unrelated as unrelated
15 git checkout
-f "$1^0" &&
16 git read-tree
-u --reset HEAD
&&
17 git clean
-d -f -f -q -x
20 test_expect_success setup
'
22 echo unrelated >unrelated &&
24 test_commit initial foo a &&
25 test_commit base foo b &&
26 test_commit picked foo c &&
27 test_commit --signoff picked-signed foo d &&
28 git checkout -b topic initial &&
29 test_commit redundant-pick foo c redundant &&
30 git commit --allow-empty --allow-empty-message &&
32 git checkout master &&
33 git config advice.detachedhead false
37 test_expect_success
'failed cherry-pick does not advance HEAD' '
38 pristine_detach initial &&
40 head=$(git rev-parse HEAD) &&
41 test_must_fail git cherry-pick picked &&
42 newhead=$(git rev-parse HEAD) &&
44 test "$head" = "$newhead"
47 test_expect_success
'advice from failed cherry-pick' "
48 pristine_detach initial &&
50 picked=\$(git rev-parse --short picked) &&
51 cat <<-EOF >expected &&
52 error: could not apply \$picked... picked
53 hint: after resolving the conflicts, mark the corrected paths
54 hint: with 'git add <paths>' or 'git rm <paths>'
55 hint: and commit the result with 'git commit'
57 test_must_fail git cherry-pick picked 2>actual &&
59 test_i18ncmp expected actual
62 test_expect_success
'advice from failed cherry-pick --no-commit' "
63 pristine_detach initial &&
65 picked=\$(git rev-parse --short picked) &&
66 cat <<-EOF >expected &&
67 error: could not apply \$picked... picked
68 hint: after resolving the conflicts, mark the corrected paths
69 hint: with 'git add <paths>' or 'git rm <paths>'
71 test_must_fail git cherry-pick --no-commit picked 2>actual &&
73 test_i18ncmp expected actual
76 test_expect_success
'failed cherry-pick sets CHERRY_PICK_HEAD' '
77 pristine_detach initial &&
78 test_must_fail git cherry-pick picked &&
79 test_cmp_rev picked CHERRY_PICK_HEAD
82 test_expect_success
'successful cherry-pick does not set CHERRY_PICK_HEAD' '
83 pristine_detach initial &&
84 git cherry-pick base &&
85 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
88 test_expect_success
'cherry-pick --no-commit does not set CHERRY_PICK_HEAD' '
89 pristine_detach initial &&
90 git cherry-pick --no-commit base &&
91 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
94 test_expect_success
'cherry-pick w/dirty tree does not set CHERRY_PICK_HEAD' '
95 pristine_detach initial &&
97 test_must_fail git cherry-pick base &&
98 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
101 test_expect_success \
102 'cherry-pick --strategy=resolve w/dirty tree does not set CHERRY_PICK_HEAD' '
103 pristine_detach initial &&
105 test_must_fail git cherry-pick --strategy=resolve base &&
106 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
109 test_expect_success
'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' '
110 pristine_detach initial &&
112 GIT_CHERRY_PICK_HELP="and then do something else" &&
113 export GIT_CHERRY_PICK_HELP &&
114 test_must_fail git cherry-pick picked
116 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
119 test_expect_success
'git reset clears CHERRY_PICK_HEAD' '
120 pristine_detach initial &&
122 test_must_fail git cherry-pick picked &&
125 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
128 test_expect_success
'failed commit does not clear CHERRY_PICK_HEAD' '
129 pristine_detach initial &&
131 test_must_fail git cherry-pick picked &&
132 test_must_fail git commit &&
134 test_cmp_rev picked CHERRY_PICK_HEAD
137 test_expect_success
'cancelled commit does not clear CHERRY_PICK_HEAD' '
138 pristine_detach initial &&
140 test_must_fail git cherry-pick picked &&
141 echo resolved >foo &&
143 git update-index --refresh -q &&
144 test_must_fail git diff-index --exit-code HEAD &&
148 test_must_fail git commit
151 test_cmp_rev picked CHERRY_PICK_HEAD
154 test_expect_success
'successful commit clears CHERRY_PICK_HEAD' '
155 pristine_detach initial &&
157 test_must_fail git cherry-pick picked &&
158 echo resolved >foo &&
162 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
165 test_expect_success
'failed cherry-pick produces dirty index' '
166 pristine_detach initial &&
168 test_must_fail git cherry-pick picked &&
170 test_must_fail git update-index --refresh -q &&
171 test_must_fail git diff-index --exit-code HEAD
174 test_expect_success
'failed cherry-pick registers participants in index' '
175 pristine_detach initial &&
177 git checkout base -- foo &&
178 git ls-files --stage foo &&
179 git checkout initial -- foo &&
180 git ls-files --stage foo &&
181 git checkout picked -- foo &&
182 git ls-files --stage foo
188 " < stages > expected &&
189 git read-tree -u --reset HEAD &&
191 test_must_fail git cherry-pick picked &&
192 git ls-files --stage --unmerged > actual &&
194 test_cmp expected actual
197 test_expect_success
'failed cherry-pick describes conflict in work tree' '
198 pristine_detach initial &&
199 cat <<-EOF > expected &&
207 test_must_fail git cherry-pick picked &&
209 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
210 test_cmp expected actual
213 test_expect_success
'diff3 -m style' '
214 pristine_detach initial &&
215 git config merge.conflictstyle diff3 &&
216 cat <<-EOF > expected &&
219 ||||||| parent of objid picked
226 test_must_fail git cherry-pick picked &&
228 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
229 test_cmp expected actual
232 test_expect_success
'revert also handles conflicts sanely' '
233 git config --unset merge.conflictstyle &&
234 pristine_detach initial &&
235 cat <<-EOF > expected &&
240 >>>>>>> parent of objid picked
243 git checkout picked -- foo &&
244 git ls-files --stage foo &&
245 git checkout initial -- foo &&
246 git ls-files --stage foo &&
247 git checkout base -- foo &&
248 git ls-files --stage foo
254 " < stages > expected-stages &&
255 git read-tree -u --reset HEAD &&
257 head=$(git rev-parse HEAD) &&
258 test_must_fail git revert picked &&
259 newhead=$(git rev-parse HEAD) &&
260 git ls-files --stage --unmerged > actual-stages &&
262 test "$head" = "$newhead" &&
263 test_must_fail git update-index --refresh -q &&
264 test_must_fail git diff-index --exit-code HEAD &&
265 test_cmp expected-stages actual-stages &&
266 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
267 test_cmp expected actual
270 test_expect_success
'failed revert sets REVERT_HEAD' '
271 pristine_detach initial &&
272 test_must_fail git revert picked &&
273 test_cmp_rev picked REVERT_HEAD
276 test_expect_success
'successful revert does not set REVERT_HEAD' '
277 pristine_detach base &&
279 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
280 test_must_fail git rev-parse --verify REVERT_HEAD
283 test_expect_success
'revert --no-commit sets REVERT_HEAD' '
284 pristine_detach base &&
285 git revert --no-commit base &&
286 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
287 test_cmp_rev base REVERT_HEAD
290 test_expect_success
'revert w/dirty tree does not set REVERT_HEAD' '
291 pristine_detach base &&
293 test_must_fail git revert base &&
294 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
295 test_must_fail git rev-parse --verify REVERT_HEAD
298 test_expect_success
'GIT_CHERRY_PICK_HELP does not suppress REVERT_HEAD' '
299 pristine_detach initial &&
301 GIT_CHERRY_PICK_HELP="and then do something else" &&
302 GIT_REVERT_HELP="and then do something else, again" &&
303 export GIT_CHERRY_PICK_HELP GIT_REVERT_HELP &&
304 test_must_fail git revert picked
306 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
307 test_cmp_rev picked REVERT_HEAD
310 test_expect_success
'git reset clears REVERT_HEAD' '
311 pristine_detach initial &&
312 test_must_fail git revert picked &&
314 test_must_fail git rev-parse --verify REVERT_HEAD
317 test_expect_success
'failed commit does not clear REVERT_HEAD' '
318 pristine_detach initial &&
319 test_must_fail git revert picked &&
320 test_must_fail git commit &&
321 test_cmp_rev picked REVERT_HEAD
324 test_expect_success
'revert conflict, diff3 -m style' '
325 pristine_detach initial &&
326 git config merge.conflictstyle diff3 &&
327 cat <<-EOF > expected &&
334 >>>>>>> parent of objid picked
337 test_must_fail git revert picked &&
339 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
340 test_cmp expected actual
343 test_expect_success
'failed cherry-pick does not forget -s' '
344 pristine_detach initial &&
345 test_must_fail git cherry-pick -s picked &&
346 test_i18ngrep -e "Signed-off-by" .git/MERGE_MSG
349 test_expect_success
'commit after failed cherry-pick does not add duplicated -s' '
350 pristine_detach initial &&
351 test_must_fail git cherry-pick -s picked-signed &&
353 test $(git show -s |grep -c "Signed-off-by") = 1
356 test_expect_success
'commit after failed cherry-pick adds -s at the right place' '
357 pristine_detach initial &&
358 test_must_fail git cherry-pick picked &&
362 # Do S-o-b and Conflicts appear in the right order?
363 cat <<-\EOF >expect &&
364 Signed-off-by: C O Mitter <committer@example.com>
367 grep -e "^# Conflicts:" -e '^Signed-off-by
' <.git/COMMIT_EDITMSG >actual &&
368 test_cmp expect actual &&
370 cat <<-\EOF >expected &&
373 Signed-off-by: C O Mitter <committer@example.com>
376 git show -s --pretty=format:%B >actual &&
377 test_cmp expected actual
380 test_expect_success
'commit --amend -s places the sign-off at the right place' '
381 pristine_detach initial &&
382 test_must_fail git cherry-pick picked &&
384 # emulate old-style conflicts block
385 mv .git/MERGE_MSG .git/MERGE_MSG+ &&
386 sed -e "/^# Conflicts:/,\$s/^# *//" <.git/MERGE_MSG+ >.git/MERGE_MSG &&
389 git commit --amend -s &&
391 # Do S-o-b and Conflicts appear in the right order?
392 cat <<-\EOF >expect &&
393 Signed-off-by: C O Mitter <committer@example.com>
396 grep -e "^Conflicts:" -e '^Signed-off-by
' <.git/COMMIT_EDITMSG >actual &&
397 test_cmp expect actual
400 test_expect_success
'cherry-pick preserves sparse-checkout' '
401 pristine_detach initial &&
402 test_config core.sparseCheckout true &&
404 echo \"/*\" >.git/info/sparse-checkout
405 git read-tree --reset -u HEAD
406 rm .git/info/sparse-checkout" &&
407 echo /unrelated >.git/info/sparse-checkout &&
408 git read-tree --reset -u HEAD &&
409 test_must_fail git cherry-pick -Xours picked>actual &&
410 test_i18ngrep ! "Changes not staged for commit:" actual
413 test_expect_success
'cherry-pick --continue remembers --keep-redundant-commits' '
414 test_when_finished "git cherry-pick --abort || :" &&
415 pristine_detach initial &&
416 test_must_fail git cherry-pick --keep-redundant-commits picked redundant &&
419 git cherry-pick --continue
422 test_expect_success
'cherry-pick --continue remembers --allow-empty and --allow-empty-message' '
423 test_when_finished "git cherry-pick --abort || :" &&
424 pristine_detach initial &&
425 test_must_fail git cherry-pick --allow-empty --allow-empty-message \
429 git cherry-pick --continue