Code

Make git-{pull,rebase} message without tracking information friendlier
[git.git] / t / t3507-cherry-pick-conflict.sh
1 #!/bin/sh
3 test_description='test cherry-pick and revert with conflicts
5   -
6   + picked: rewrites foo to c
7   + base: rewrites foo to b
8   + initial: writes foo as a, unrelated as unrelated
10 '
12 . ./test-lib.sh
14 test_cmp_rev () {
15         git rev-parse --verify "$1" >expect.rev &&
16         git rev-parse --verify "$2" >actual.rev &&
17         test_cmp expect.rev actual.rev
18 }
20 pristine_detach () {
21         git checkout -f "$1^0" &&
22         git read-tree -u --reset HEAD &&
23         git clean -d -f -f -q -x
24 }
26 test_expect_success setup '
28         echo unrelated >unrelated &&
29         git add unrelated &&
30         test_commit initial foo a &&
31         test_commit base foo b &&
32         test_commit picked foo c &&
33         git config advice.detachedhead false
35 '
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"
45 '
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'
56         EOF
57         test_must_fail git cherry-pick picked 2>actual &&
59         test_i18ncmp expected actual
60 "
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>'
70         EOF
71         test_must_fail git cherry-pick --no-commit picked 2>actual &&
73         test_i18ncmp expected actual
74 "
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
80 '
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
86 '
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
92 '
94 test_expect_success 'cherry-pick w/dirty tree does not set CHERRY_PICK_HEAD' '
95         pristine_detach initial &&
96         echo foo > foo &&
97         test_must_fail git cherry-pick base &&
98         test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
99 '
101 test_expect_success \
102         'cherry-pick --strategy=resolve w/dirty tree does not set CHERRY_PICK_HEAD' '
103         pristine_detach initial &&
104         echo foo > foo &&
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 &&
111         (
112                 GIT_CHERRY_PICK_HELP="and then do something else" &&
113                 export GIT_CHERRY_PICK_HELP &&
114                 test_must_fail git cherry-pick picked
115         ) &&
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 &&
123         git reset &&
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 &&
142         git add foo &&
143         git update-index --refresh -q &&
144         test_must_fail git diff-index --exit-code HEAD &&
145         (
146                 GIT_EDITOR=false &&
147                 export GIT_EDITOR &&
148                 test_must_fail git commit
149         ) &&
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 &&
159         git add foo &&
160         git commit &&
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 &&
176         {
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
183         } > stages &&
184         sed "
185                 1 s/ 0  / 1     /
186                 2 s/ 0  / 2     /
187                 3 s/ 0  / 3     /
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 &&
200         <<<<<<< HEAD
201         a
202         =======
203         c
204         >>>>>>> objid picked
205         EOF
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 &&
217         <<<<<<< HEAD
218         a
219         ||||||| parent of objid picked
220         b
221         =======
222         c
223         >>>>>>> objid picked
224         EOF
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 &&
236         <<<<<<< HEAD
237         a
238         =======
239         b
240         >>>>>>> parent of objid picked
241         EOF
242         {
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
249         } > stages &&
250         sed "
251                 1 s/ 0  / 1     /
252                 2 s/ 0  / 2     /
253                 3 s/ 0  / 3     /
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 &&
278         git revert 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 &&
292         echo foo > foo &&
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 &&
300         (
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
305         ) &&
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 &&
313         git reset &&
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 &&
328         <<<<<<< HEAD
329         a
330         ||||||| objid picked
331         c
332         =======
333         b
334         >>>>>>> parent of objid picked
335         EOF
337         test_must_fail git revert picked &&
339         sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
340         test_cmp expected actual
343 test_done