core.hidedotfiles: hide '.git' dir by default
[git/dscho.git] / t / t3507-cherry-pick-conflict.sh
blobee1659c17810d2c9ce7836582a80fd3d0d89ca24
1 #!/bin/sh
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
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
20 pristine_detach () {
21 git checkout -f "$1^0" &&
22 git read-tree -u --reset HEAD &&
23 git clean -d -f -f -q -x
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
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'
56 EOF
57 test_must_fail git cherry-pick picked 2>actual &&
59 test_i18ncmp expected actual
62 test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' '
63 pristine_detach initial &&
64 test_must_fail git cherry-pick picked &&
65 test_cmp_rev picked CHERRY_PICK_HEAD
68 test_expect_success 'successful cherry-pick does not set CHERRY_PICK_HEAD' '
69 pristine_detach initial &&
70 git cherry-pick base &&
71 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
74 test_expect_success 'cherry-pick --no-commit does not set CHERRY_PICK_HEAD' '
75 pristine_detach initial &&
76 git cherry-pick --no-commit base &&
77 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
80 test_expect_success 'cherry-pick w/dirty tree does not set CHERRY_PICK_HEAD' '
81 pristine_detach initial &&
82 echo foo > foo &&
83 test_must_fail git cherry-pick base &&
84 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
87 test_expect_success \
88 'cherry-pick --strategy=resolve w/dirty tree does not set CHERRY_PICK_HEAD' '
89 pristine_detach initial &&
90 echo foo > foo &&
91 test_must_fail git cherry-pick --strategy=resolve base &&
92 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
95 test_expect_success 'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' '
96 pristine_detach initial &&
98 GIT_CHERRY_PICK_HELP="and then do something else" &&
99 export GIT_CHERRY_PICK_HELP &&
100 test_must_fail git cherry-pick picked
101 ) &&
102 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
105 test_expect_success 'git reset clears CHERRY_PICK_HEAD' '
106 pristine_detach initial &&
108 test_must_fail git cherry-pick picked &&
109 git reset &&
111 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
114 test_expect_success 'failed commit does not clear CHERRY_PICK_HEAD' '
115 pristine_detach initial &&
117 test_must_fail git cherry-pick picked &&
118 test_must_fail git commit &&
120 test_cmp_rev picked CHERRY_PICK_HEAD
123 test_expect_success 'cancelled commit does not clear CHERRY_PICK_HEAD' '
124 pristine_detach initial &&
126 test_must_fail git cherry-pick picked &&
127 echo resolved >foo &&
128 git add foo &&
129 git update-index --refresh -q &&
130 test_must_fail git diff-index --exit-code HEAD &&
132 GIT_EDITOR=false &&
133 export GIT_EDITOR &&
134 test_must_fail git commit
135 ) &&
137 test_cmp_rev picked CHERRY_PICK_HEAD
140 test_expect_success 'successful commit clears CHERRY_PICK_HEAD' '
141 pristine_detach initial &&
143 test_must_fail git cherry-pick picked &&
144 echo resolved >foo &&
145 git add foo &&
146 git commit &&
148 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD
151 test_expect_success 'failed cherry-pick produces dirty index' '
152 pristine_detach initial &&
154 test_must_fail git cherry-pick picked &&
156 test_must_fail git update-index --refresh -q &&
157 test_must_fail git diff-index --exit-code HEAD
160 test_expect_success 'failed cherry-pick registers participants in index' '
161 pristine_detach initial &&
163 git checkout base -- foo &&
164 git ls-files --stage foo &&
165 git checkout initial -- foo &&
166 git ls-files --stage foo &&
167 git checkout picked -- foo &&
168 git ls-files --stage foo
169 } > stages &&
170 sed "
171 1 s/ 0 / 1 /
172 2 s/ 0 / 2 /
173 3 s/ 0 / 3 /
174 " < stages > expected &&
175 git read-tree -u --reset HEAD &&
177 test_must_fail git cherry-pick picked &&
178 git ls-files --stage --unmerged > actual &&
180 test_cmp expected actual
183 test_expect_success 'failed cherry-pick describes conflict in work tree' '
184 pristine_detach initial &&
185 cat <<-EOF > expected &&
186 <<<<<<< HEAD
188 =======
190 >>>>>>> objid picked
193 test_must_fail git cherry-pick picked &&
195 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
196 test_cmp expected actual
199 test_expect_success 'diff3 -m style' '
200 pristine_detach initial &&
201 git config merge.conflictstyle diff3 &&
202 cat <<-EOF > expected &&
203 <<<<<<< HEAD
205 ||||||| parent of objid picked
207 =======
209 >>>>>>> objid picked
212 test_must_fail git cherry-pick picked &&
214 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
215 test_cmp expected actual
218 test_expect_success 'revert also handles conflicts sanely' '
219 git config --unset merge.conflictstyle &&
220 pristine_detach initial &&
221 cat <<-EOF > expected &&
222 <<<<<<< HEAD
224 =======
226 >>>>>>> parent of objid picked
229 git checkout picked -- foo &&
230 git ls-files --stage foo &&
231 git checkout initial -- foo &&
232 git ls-files --stage foo &&
233 git checkout base -- foo &&
234 git ls-files --stage foo
235 } > stages &&
236 sed "
237 1 s/ 0 / 1 /
238 2 s/ 0 / 2 /
239 3 s/ 0 / 3 /
240 " < stages > expected-stages &&
241 git read-tree -u --reset HEAD &&
243 head=$(git rev-parse HEAD) &&
244 test_must_fail git revert picked &&
245 newhead=$(git rev-parse HEAD) &&
246 git ls-files --stage --unmerged > actual-stages &&
248 test "$head" = "$newhead" &&
249 test_must_fail git update-index --refresh -q &&
250 test_must_fail git diff-index --exit-code HEAD &&
251 test_cmp expected-stages actual-stages &&
252 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
253 test_cmp expected actual
256 test_expect_success 'failed revert sets REVERT_HEAD' '
257 pristine_detach initial &&
258 test_must_fail git revert picked &&
259 test_cmp_rev picked REVERT_HEAD
262 test_expect_success 'successful revert does not set REVERT_HEAD' '
263 pristine_detach base &&
264 git revert base &&
265 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
266 test_must_fail git rev-parse --verify REVERT_HEAD
269 test_expect_success 'revert --no-commit sets REVERT_HEAD' '
270 pristine_detach base &&
271 git revert --no-commit base &&
272 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
273 test_cmp_rev base REVERT_HEAD
276 test_expect_success 'revert w/dirty tree does not set REVERT_HEAD' '
277 pristine_detach base &&
278 echo foo > foo &&
279 test_must_fail git revert base &&
280 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
281 test_must_fail git rev-parse --verify REVERT_HEAD
284 test_expect_success 'GIT_CHERRY_PICK_HELP does not suppress REVERT_HEAD' '
285 pristine_detach initial &&
287 GIT_CHERRY_PICK_HELP="and then do something else" &&
288 GIT_REVERT_HELP="and then do something else, again" &&
289 export GIT_CHERRY_PICK_HELP GIT_REVERT_HELP &&
290 test_must_fail git revert picked
291 ) &&
292 test_must_fail git rev-parse --verify CHERRY_PICK_HEAD &&
293 test_cmp_rev picked REVERT_HEAD
296 test_expect_success 'git reset clears REVERT_HEAD' '
297 pristine_detach initial &&
298 test_must_fail git revert picked &&
299 git reset &&
300 test_must_fail git rev-parse --verify REVERT_HEAD
303 test_expect_success 'failed commit does not clear REVERT_HEAD' '
304 pristine_detach initial &&
305 test_must_fail git revert picked &&
306 test_must_fail git commit &&
307 test_cmp_rev picked REVERT_HEAD
310 test_expect_success 'revert conflict, diff3 -m style' '
311 pristine_detach initial &&
312 git config merge.conflictstyle diff3 &&
313 cat <<-EOF > expected &&
314 <<<<<<< HEAD
316 ||||||| objid picked
318 =======
320 >>>>>>> parent of objid picked
323 test_must_fail git revert picked &&
325 sed "s/[a-f0-9]*\.\.\./objid/" foo > actual &&
326 test_cmp expected actual
329 test_done