t6036, t6042: use test_create_repo to keep tests independent

These tests used pretty strong measures to get a clean slate: git rm -rf . && git clean -fdqx && rm -rf .git && git init && It's easier, safer (what if a previous test has a bug and accidentally changes into a directory outside the test path?), and allows re-inspecting test setup later if we instead just use test_create_repo to put different tests into separate sub-repositories. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed May 24, 2018 at 00:04 UTC 2a4c19efbf8953cccc28cbf359049caff907a4e6
2 files changed +926 -815
t/t6036-recursive-corner-cases.sh
+452 -402
@@ -21,51 +21,60 @@ get_clean_checkout () {
21 #
22
23 test_expect_success 'setup basic criss-cross + rename with no modifications' '
24 - ten="0 1 2 3 4 5 6 7 8 9" &&
25 - for i in $ten
26 - do
27 - echo line $i in a sample file
28 - done >one &&
29 - for i in $ten
30 - do
31 - echo line $i in another sample file
32 - done >two &&
33 - git add one two &&
34 - test_tick && git commit -m initial &&
35 -
36 - git branch L1 &&
37 - git checkout -b R1 &&
38 - git mv one three &&
39 - test_tick && git commit -m R1 &&
40 -
41 - git checkout L1 &&
42 - git mv two three &&
43 - test_tick && git commit -m L1 &&
44 -
45 - git checkout L1^0 &&
46 - test_tick && git merge -s ours R1 &&
47 - git tag L2 &&
48 -
49 - git checkout R1^0 &&
50 - test_tick && git merge -s ours L1 &&
51 - git tag R2
24 + test_create_repo basic-rename &&
25 + (
26 + cd basic-rename &&
27 +
28 + ten="0 1 2 3 4 5 6 7 8 9" &&
29 + for i in $ten
30 + do
31 + echo line $i in a sample file
32 + done >one &&
33 + for i in $ten
34 + do
35 + echo line $i in another sample file
36 + done >two &&
37 + git add one two &&
38 + test_tick && git commit -m initial &&
39 +
40 + git branch L1 &&
41 + git checkout -b R1 &&
42 + git mv one three &&
43 + test_tick && git commit -m R1 &&
44 +
45 + git checkout L1 &&
46 + git mv two three &&
47 + test_tick && git commit -m L1 &&
48 +
49 + git checkout L1^0 &&
50 + test_tick && git merge -s ours R1 &&
51 + git tag L2 &&
52 +
53 + git checkout R1^0 &&
54 + test_tick && git merge -s ours L1 &&
55 + git tag R2
56 + )
57 '
58
59 test_expect_success 'merge simple rename+criss-cross with no modifications' '
55 - git reset --hard &&
56 - git checkout L2^0 &&
60 + (
61 + cd basic-rename &&
62 +
63 + git reset --hard &&
64 + git checkout L2^0 &&
65
58 - test_must_fail git merge -s recursive R2^0 &&
66 + test_must_fail git merge -s recursive R2^0 &&
67
60 - test 2 = $(git ls-files -s | wc -l) &&
61 - test 2 = $(git ls-files -u | wc -l) &&
62 - test 2 = $(git ls-files -o | wc -l) &&
68 + test 2 = $(git ls-files -s | wc -l) &&
69 + test 2 = $(git ls-files -u | wc -l) &&
70 + test 2 = $(git ls-files -o | wc -l) &&
71
64 - test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
65 - test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
72 + test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
73 + test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
74
67 - test $(git rev-parse L2:three) = $(git hash-object three~HEAD) &&
68 - test $(git rev-parse R2:three) = $(git hash-object three~R2^0)
75 + test $(git rev-parse L2:three) = $(git hash-object three~HEAD) &&
76 + test $(git rev-parse R2:three) = $(git hash-object three~R2^0)
77 + )
78 '
79
80 #
@@ -81,58 +90,61 @@ test_expect_success 'merge simple rename+criss-cross with no modifications' '
90 #
91
92 test_expect_success 'setup criss-cross + rename merges with basic modification' '
84 - git rm -rf . &&
85 - git clean -fdqx &&
86 - rm -rf .git &&
87 - git init &&
88 -
89 - ten="0 1 2 3 4 5 6 7 8 9" &&
90 - for i in $ten
91 - do
92 - echo line $i in a sample file
93 - done >one &&
94 - for i in $ten
95 - do
96 - echo line $i in another sample file
97 - done >two &&
98 - git add one two &&
99 - test_tick && git commit -m initial &&
100 -
101 - git branch L1 &&
102 - git checkout -b R1 &&
103 - git mv one three &&
104 - echo more >>two &&
105 - git add two &&
106 - test_tick && git commit -m R1 &&
107 -
108 - git checkout L1 &&
109 - git mv two three &&
110 - test_tick && git commit -m L1 &&
111 -
112 - git checkout L1^0 &&
113 - test_tick && git merge -s ours R1 &&
114 - git tag L2 &&
115 -
116 - git checkout R1^0 &&
117 - test_tick && git merge -s ours L1 &&
118 - git tag R2
93 + test_create_repo rename-modify &&
94 + (
95 + cd rename-modify &&
96 +
97 + ten="0 1 2 3 4 5 6 7 8 9" &&
98 + for i in $ten
99 + do
100 + echo line $i in a sample file
101 + done >one &&
102 + for i in $ten
103 + do
104 + echo line $i in another sample file
105 + done >two &&
106 + git add one two &&
107 + test_tick && git commit -m initial &&
108 +
109 + git branch L1 &&
110 + git checkout -b R1 &&
111 + git mv one three &&
112 + echo more >>two &&
113 + git add two &&
114 + test_tick && git commit -m R1 &&
115 +
116 + git checkout L1 &&
117 + git mv two three &&
118 + test_tick && git commit -m L1 &&
119 +
120 + git checkout L1^0 &&
121 + test_tick && git merge -s ours R1 &&
122 + git tag L2 &&
123 +
124 + git checkout R1^0 &&
125 + test_tick && git merge -s ours L1 &&
126 + git tag R2
127 + )
128 '
129
130 test_expect_success 'merge criss-cross + rename merges with basic modification' '
122 - git reset --hard &&
123 - git checkout L2^0 &&
131 + (
132 + cd rename-modify &&
133 +
134 + git checkout L2^0 &&
135
125 - test_must_fail git merge -s recursive R2^0 &&
136 + test_must_fail git merge -s recursive R2^0 &&
137
127 - test 2 = $(git ls-files -s | wc -l) &&
128 - test 2 = $(git ls-files -u | wc -l) &&
129 - test 2 = $(git ls-files -o | wc -l) &&
138 + test 2 = $(git ls-files -s | wc -l) &&
139 + test 2 = $(git ls-files -u | wc -l) &&
140 + test 2 = $(git ls-files -o | wc -l) &&
141
131 - test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
132 - test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
142 + test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
143 + test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
144
134 - test $(git rev-parse L2:three) = $(git hash-object three~HEAD) &&
135 - test $(git rev-parse R2:three) = $(git hash-object three~R2^0)
145 + test $(git rev-parse L2:three) = $(git hash-object three~HEAD) &&
146 + test $(git rev-parse R2:three) = $(git hash-object three~R2^0)
147 + )
148 '
149
150 #
@@ -156,64 +168,67 @@ test_expect_success 'merge criss-cross + rename merges with basic modification'
168 #
169
170 test_expect_success 'setup differently handled merges of rename/add conflict' '
159 - git rm -rf . &&
160 - git clean -fdqx &&
161 - rm -rf .git &&
162 - git init &&
163 -
164 - printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" >a &&
165 - git add a &&
166 - test_tick && git commit -m A &&
167 -
168 - git branch B &&
169 - git checkout -b C &&
170 - echo 10 >>a &&
171 - echo "other content" >>new_a &&
172 - git add a new_a &&
173 - test_tick && git commit -m C &&
174 -
175 - git checkout B &&
176 - git mv a new_a &&
177 - test_tick && git commit -m B &&
178 -
179 - git checkout B^0 &&
180 - test_must_fail git merge C &&
181 - git clean -f &&
182 - test_tick && git commit -m D &&
183 - git tag D &&
184 -
185 - git checkout C^0 &&
186 - test_must_fail git merge B &&
187 - rm new_a~HEAD new_a &&
188 - printf "Incorrectly merged content" >>new_a &&
189 - git add -u &&
190 - test_tick && git commit -m E &&
191 - git tag E
171 + test_create_repo rename-add &&
172 + (
173 + cd rename-add &&
174 +
175 + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" >a &&
176 + git add a &&
177 + test_tick && git commit -m A &&
178 +
179 + git branch B &&
180 + git checkout -b C &&
181 + echo 10 >>a &&
182 + echo "other content" >>new_a &&
183 + git add a new_a &&
184 + test_tick && git commit -m C &&
185 +
186 + git checkout B &&
187 + git mv a new_a &&
188 + test_tick && git commit -m B &&
189 +
190 + git checkout B^0 &&
191 + test_must_fail git merge C &&
192 + git clean -f &&
193 + test_tick && git commit -m D &&
194 + git tag D &&
195 +
196 + git checkout C^0 &&
197 + test_must_fail git merge B &&
198 + rm new_a~HEAD new_a &&
199 + printf "Incorrectly merged content" >>new_a &&
200 + git add -u &&
201 + test_tick && git commit -m E &&
202 + git tag E
203 + )
204 '
205
206 test_expect_success 'git detects differently handled merges conflict' '
195 - git reset --hard &&
196 - git checkout D^0 &&
197 -
198 - test_must_fail git merge -s recursive E^0 &&
199 -
200 - test 3 = $(git ls-files -s | wc -l) &&
201 - test 3 = $(git ls-files -u | wc -l) &&
202 - test 0 = $(git ls-files -o | wc -l) &&
203 -
204 - test $(git rev-parse :2:new_a) = $(git rev-parse D:new_a) &&
205 - test $(git rev-parse :3:new_a) = $(git rev-parse E:new_a) &&
206 -
207 - git cat-file -p B:new_a >>merged &&
208 - git cat-file -p C:new_a >>merge-me &&
209 - >empty &&
210 - test_must_fail git merge-file \
211 - -L "Temporary merge branch 2" \
212 - -L "" \
213 - -L "Temporary merge branch 1" \
214 - merged empty merge-me &&
215 - sed -e "s/^\([<=>]\)/\1\1\1/" merged >merged-internal &&
216 - test $(git rev-parse :1:new_a) = $(git hash-object merged-internal)
207 + (
208 + cd rename-add &&
209 +
210 + git checkout D^0 &&
211 +
212 + test_must_fail git merge -s recursive E^0 &&
213 +
214 + test 3 = $(git ls-files -s | wc -l) &&
215 + test 3 = $(git ls-files -u | wc -l) &&
216 + test 0 = $(git ls-files -o | wc -l) &&
217 +
218 + test $(git rev-parse :2:new_a) = $(git rev-parse D:new_a) &&
219 + test $(git rev-parse :3:new_a) = $(git rev-parse E:new_a) &&
220 +
221 + git cat-file -p B:new_a >>merged &&
222 + git cat-file -p C:new_a >>merge-me &&
223 + >empty &&
224 + test_must_fail git merge-file \
225 + -L "Temporary merge branch 2" \
226 + -L "" \
227 + -L "Temporary merge branch 1" \
228 + merged empty merge-me &&
229 + sed -e "s/^\([<=>]\)/\1\1\1/" merged >merged-internal &&
230 + test $(git rev-parse :1:new_a) = $(git hash-object merged-internal)
231 + )
232 '
233
234 #
@@ -236,67 +251,75 @@ test_expect_success 'git detects differently handled merges conflict' '
251 # Merging commits D & E should result in modify/delete conflict.
252
253 test_expect_success 'setup criss-cross + modify/delete resolved differently' '
239 - git rm -rf . &&
240 - git clean -fdqx &&
241 - rm -rf .git &&
242 - git init &&
243 -
244 - echo A >file &&
245 - git add file &&
246 - test_tick &&
247 - git commit -m A &&
248 -
249 - git branch B &&
250 - git checkout -b C &&
251 - git rm file &&
252 - test_tick &&
253 - git commit -m C &&
254 -
255 - git checkout B &&
256 - echo B >file &&
257 - git add file &&
258 - test_tick &&
259 - git commit -m B &&
260 -
261 - git checkout B^0 &&
262 - test_must_fail git merge C &&
263 - echo B >file &&
264 - git add file &&
265 - test_tick &&
266 - git commit -m D &&
267 - git tag D &&
268 -
269 - git checkout C^0 &&
270 - test_must_fail git merge B &&
271 - git rm file &&
272 - test_tick &&
273 - git commit -m E &&
274 - git tag E
254 + test_create_repo modify-delete &&
255 + (
256 + cd modify-delete &&
257 +
258 + echo A >file &&
259 + git add file &&
260 + test_tick &&
261 + git commit -m A &&
262 +
263 + git branch B &&
264 + git checkout -b C &&
265 + git rm file &&
266 + test_tick &&
267 + git commit -m C &&
268 +
269 + git checkout B &&
270 + echo B >file &&
271 + git add file &&
272 + test_tick &&
273 + git commit -m B &&
274 +
275 + git checkout B^0 &&
276 + test_must_fail git merge C &&
277 + echo B >file &&
278 + git add file &&
279 + test_tick &&
280 + git commit -m D &&
281 + git tag D &&
282 +
283 + git checkout C^0 &&
284 + test_must_fail git merge B &&
285 + git rm file &&
286 + test_tick &&
287 + git commit -m E &&
288 + git tag E
289 + )
290 '
291
292 test_expect_success 'git detects conflict merging criss-cross+modify/delete' '
278 - git checkout D^0 &&
293 + (
294 + cd modify-delete &&
295 +
296 + git checkout D^0 &&
297
280 - test_must_fail git merge -s recursive E^0 &&
298 + test_must_fail git merge -s recursive E^0 &&
299
282 - test 2 -eq $(git ls-files -s | wc -l) &&
283 - test 2 -eq $(git ls-files -u | wc -l) &&
300 + test 2 -eq $(git ls-files -s | wc -l) &&
301 + test 2 -eq $(git ls-files -u | wc -l) &&
302
285 - test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
286 - test $(git rev-parse :2:file) = $(git rev-parse B:file)
303 + test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
304 + test $(git rev-parse :2:file) = $(git rev-parse B:file)
305 + )
306 '
307
308 test_expect_success 'git detects conflict merging criss-cross+modify/delete, reverse direction' '
290 - git reset --hard &&
291 - git checkout E^0 &&
309 + (
310 + cd modify-delete &&
311 +
312 + git reset --hard &&
313 + git checkout E^0 &&
314
293 - test_must_fail git merge -s recursive D^0 &&
315 + test_must_fail git merge -s recursive D^0 &&
316
295 - test 2 -eq $(git ls-files -s | wc -l) &&
296 - test 2 -eq $(git ls-files -u | wc -l) &&
317 + test 2 -eq $(git ls-files -s | wc -l) &&
318 + test 2 -eq $(git ls-files -u | wc -l) &&
319
298 - test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
299 - test $(git rev-parse :3:file) = $(git rev-parse B:file)
320 + test $(git rev-parse :1:file) = $(git rev-parse master:file) &&
321 + test $(git rev-parse :3:file) = $(git rev-parse B:file)
322 + )
323 '
324
325 #
@@ -336,120 +359,136 @@ test_expect_success 'git detects conflict merging criss-cross+modify/delete, rev
359 #
360
361 test_expect_success 'setup differently handled merges of directory/file conflict' '
339 - git rm -rf . &&
340 - git clean -fdqx &&
341 - rm -rf .git &&
342 - git init &&
343 -
344 - >ignore-me &&
345 - git add ignore-me &&
346 - test_tick &&
347 - git commit -m A &&
348 - git tag A &&
349 -
350 - git branch B &&
351 - git checkout -b C &&
352 - mkdir a &&
353 - echo 10 >a/file &&
354 - git add a/file &&
355 - test_tick &&
356 - git commit -m C &&
357 -
358 - git checkout B &&
359 - echo 5 >a &&
360 - git add a &&
361 - test_tick &&
362 - git commit -m B &&
363 -
364 - git checkout B^0 &&
365 - test_must_fail git merge C &&
366 - git clean -f &&
367 - rm -rf a/ &&
368 - echo 5 >a &&
369 - git add a &&
370 - test_tick &&
371 - git commit -m D &&
372 - git tag D &&
373 -
374 - git checkout C^0 &&
375 - test_must_fail git merge B &&
376 - git clean -f &&
377 - git rm --cached a &&
378 - echo 10 >a/file &&
379 - git add a/file &&
380 - test_tick &&
381 - git commit -m E1 &&
382 - git tag E1 &&
383 -
384 - git checkout C^0 &&
385 - test_must_fail git merge B &&
386 - git clean -f &&
387 - git rm --cached a &&
388 - printf "10\n11\n" >a/file &&
389 - git add a/file &&
390 - test_tick &&
391 - git commit -m E2 &&
392 - git tag E2
362 + test_create_repo directory-file &&
363 + (
364 + cd directory-file &&
365 +
366 + >ignore-me &&
367 + git add ignore-me &&
368 + test_tick &&
369 + git commit -m A &&
370 + git tag A &&
371 +
372 + git branch B &&
373 + git checkout -b C &&
374 + mkdir a &&
375 + echo 10 >a/file &&
376 + git add a/file &&
377 + test_tick &&
378 + git commit -m C &&
379 +
380 + git checkout B &&
381 + echo 5 >a &&
382 + git add a &&
383 + test_tick &&
384 + git commit -m B &&
385 +
386 + git checkout B^0 &&
387 + test_must_fail git merge C &&
388 + git clean -f &&
389 + rm -rf a/ &&
390 + echo 5 >a &&
391 + git add a &&
392 + test_tick &&
393 + git commit -m D &&
394 + git tag D &&
395 +
396 + git checkout C^0 &&
397 + test_must_fail git merge B &&
398 + git clean -f &&
399 + git rm --cached a &&
400 + echo 10 >a/file &&
401 + git add a/file &&
402 + test_tick &&
403 + git commit -m E1 &&
404 + git tag E1 &&
405 +
406 + git checkout C^0 &&
407 + test_must_fail git merge B &&
408 + git clean -f &&
409 + git rm --cached a &&
410 + printf "10\n11\n" >a/file &&
411 + git add a/file &&
412 + test_tick &&
413 + git commit -m E2 &&
414 + git tag E2
415 + )
416 '
417
418 test_expect_success 'merge of D & E1 fails but has appropriate contents' '
396 - get_clean_checkout D^0 &&
419 + (
420 + cd directory-file &&
421
398 - test_must_fail git merge -s recursive E1^0 &&
422 + get_clean_checkout D^0 &&
423
400 - test 2 -eq $(git ls-files -s | wc -l) &&
401 - test 1 -eq $(git ls-files -u | wc -l) &&
402 - test 0 -eq $(git ls-files -o | wc -l) &&
424 + test_must_fail git merge -s recursive E1^0 &&
425
404 - test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
405 - test $(git rev-parse :2:a) = $(git rev-parse B:a)
426 + test 2 -eq $(git ls-files -s | wc -l) &&
427 + test 1 -eq $(git ls-files -u | wc -l) &&
428 + test 0 -eq $(git ls-files -o | wc -l) &&
429 +
430 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
431 + test $(git rev-parse :2:a) = $(git rev-parse B:a)
432 + )
433 '
434
435 test_expect_success 'merge of E1 & D fails but has appropriate contents' '
409 - get_clean_checkout E1^0 &&
436 + (
437 + cd directory-file &&
438 +
439 + get_clean_checkout E1^0 &&
440
411 - test_must_fail git merge -s recursive D^0 &&
441 + test_must_fail git merge -s recursive D^0 &&
442
413 - test 2 -eq $(git ls-files -s | wc -l) &&
414 - test 1 -eq $(git ls-files -u | wc -l) &&
415 - test 0 -eq $(git ls-files -o | wc -l) &&
443 + test 2 -eq $(git ls-files -s | wc -l) &&
444 + test 1 -eq $(git ls-files -u | wc -l) &&
445 + test 0 -eq $(git ls-files -o | wc -l) &&
446
417 - test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
418 - test $(git rev-parse :3:a) = $(git rev-parse B:a)
447 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
448 + test $(git rev-parse :3:a) = $(git rev-parse B:a)
449 + )
450 '
451
452 test_expect_success 'merge of D & E2 fails but has appropriate contents' '
422 - get_clean_checkout D^0 &&
453 + (
454 + cd directory-file &&
455 +
456 + get_clean_checkout D^0 &&
457
424 - test_must_fail git merge -s recursive E2^0 &&
458 + test_must_fail git merge -s recursive E2^0 &&
459
426 - test 4 -eq $(git ls-files -s | wc -l) &&
427 - test 3 -eq $(git ls-files -u | wc -l) &&
428 - test 1 -eq $(git ls-files -o | wc -l) &&
460 + test 4 -eq $(git ls-files -s | wc -l) &&
461 + test 3 -eq $(git ls-files -u | wc -l) &&
462 + test 1 -eq $(git ls-files -o | wc -l) &&
463
430 - test $(git rev-parse :2:a) = $(git rev-parse B:a) &&
431 - test $(git rev-parse :3:a/file) = $(git rev-parse E2:a/file) &&
432 - test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) &&
433 - test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
464 + test $(git rev-parse :2:a) = $(git rev-parse B:a) &&
465 + test $(git rev-parse :3:a/file) = $(git rev-parse E2:a/file) &&
466 + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) &&
467 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
468
435 - test -f a~HEAD
469 + test -f a~HEAD
470 + )
471 '
472
473 test_expect_success 'merge of E2 & D fails but has appropriate contents' '
439 - get_clean_checkout E2^0 &&
474 + (
475 + cd directory-file &&
476
441 - test_must_fail git merge -s recursive D^0 &&
477 + get_clean_checkout E2^0 &&
478
443 - test 4 -eq $(git ls-files -s | wc -l) &&
444 - test 3 -eq $(git ls-files -u | wc -l) &&
445 - test 1 -eq $(git ls-files -o | wc -l) &&
479 + test_must_fail git merge -s recursive D^0 &&
480
447 - test $(git rev-parse :3:a) = $(git rev-parse B:a) &&
448 - test $(git rev-parse :2:a/file) = $(git rev-parse E2:a/file) &&
449 - test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) &&
450 - test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
481 + test 4 -eq $(git ls-files -s | wc -l) &&
482 + test 3 -eq $(git ls-files -u | wc -l) &&
483 + test 1 -eq $(git ls-files -o | wc -l) &&
484
452 - test -f a~D^0
485 + test $(git rev-parse :3:a) = $(git rev-parse B:a) &&
486 + test $(git rev-parse :2:a/file) = $(git rev-parse E2:a/file) &&
487 + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) &&
488 + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) &&
489 +
490 + test -f a~D^0
491 + )
492 '
493
494 #
@@ -492,52 +531,55 @@ test_expect_success 'merge of E2 & D fails but has appropriate contents' '
531 # but that may cancel out at the final merge stage".
532
533 test_expect_success 'setup rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
495 - git reset --hard &&
496 - git rm -rf . &&
497 - git clean -fdqx &&
498 - rm -rf .git &&
499 - git init &&
500 -
501 - printf "1\n2\n3\n4\n5\n6\n" >a &&
502 - git add a &&
503 - git commit -m A &&
504 - git tag A &&
505 -
506 - git checkout -b B A &&
507 - git mv a b &&
508 - echo 7 >>b &&
509 - git add -u &&
510 - git commit -m B &&
511 -
512 - git checkout -b C A &&
513 - git mv a c &&
514 - git commit -m C &&
515 -
516 - git checkout -q B^0 &&
517 - git merge --no-commit -s ours C^0 &&
518 - git mv b newname &&
519 - git commit -m "Merge commit C^0 into HEAD" &&
520 - git tag D &&
521 -
522 - git checkout -q C^0 &&
523 - git merge --no-commit -s ours B^0 &&
524 - git mv c newname &&
525 - printf "7\n8\n" >>newname &&
526 - git add -u &&
527 - git commit -m "Merge commit B^0 into HEAD" &&
528 - git tag E
534 + test_create_repo rename-squared-squared &&
535 + (
536 + cd rename-squared-squared &&
537 +
538 + printf "1\n2\n3\n4\n5\n6\n" >a &&
539 + git add a &&
540 + git commit -m A &&
541 + git tag A &&
542 +
543 + git checkout -b B A &&
544 + git mv a b &&
545 + echo 7 >>b &&
546 + git add -u &&
547 + git commit -m B &&
548 +
549 + git checkout -b C A &&
550 + git mv a c &&
551 + git commit -m C &&
552 +
553 + git checkout -q B^0 &&
554 + git merge --no-commit -s ours C^0 &&
555 + git mv b newname &&
556 + git commit -m "Merge commit C^0 into HEAD" &&
557 + git tag D &&
558 +
559 + git checkout -q C^0 &&
560 + git merge --no-commit -s ours B^0 &&
561 + git mv c newname &&
562 + printf "7\n8\n" >>newname &&
563 + git add -u &&
564 + git commit -m "Merge commit B^0 into HEAD" &&
565 + git tag E
566 + )
567 '
568
569 test_expect_success 'handle rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' '
532 - git checkout D^0 &&
570 + (
571 + cd rename-squared-squared &&
572
534 - git merge -s recursive E^0 &&
573 + git checkout D^0 &&
574
536 - test 1 -eq $(git ls-files -s | wc -l) &&
537 - test 0 -eq $(git ls-files -u | wc -l) &&
538 - test 0 -eq $(git ls-files -o | wc -l) &&
575 + git merge -s recursive E^0 &&
576
540 - test $(git rev-parse HEAD:newname) = $(git rev-parse E:newname)
577 + test 1 -eq $(git ls-files -s | wc -l) &&
578 + test 0 -eq $(git ls-files -u | wc -l) &&
579 + test 0 -eq $(git ls-files -o | wc -l) &&
580 +
581 + test $(git rev-parse HEAD:newname) = $(git rev-parse E:newname)
582 + )
583 '
584
585 #
@@ -562,59 +604,63 @@ test_expect_success 'handle rename/rename(1to2)/modify followed by what looks li
604 # renaming carefully (both in the virtual merge base and later), and getting
605 # content merge handled.
606
565 -test_expect_success 'setup criss-cross + rename/rename/add + modify/modify' '
566 - git rm -rf . &&
567 - git clean -fdqx &&
568 - rm -rf .git &&
569 - git init &&
570 -
571 - printf "lots\nof\nwords\nand\ncontent\n" >a &&
572 - git add a &&
573 - git commit -m A &&
574 - git tag A &&
575 -
576 - git checkout -b B A &&
577 - git mv a b &&
578 - git commit -m B &&
579 -
580 - git checkout -b C A &&
581 - git mv a c &&
582 - printf "2\n3\n4\n5\n6\n7\n" >a &&
583 - git add a &&
584 - git commit -m C &&
585 -
586 - git checkout B^0 &&
587 - git merge --no-commit -s ours C^0 &&
588 - git checkout C -- a c &&
589 - mv a old_a &&
590 - echo 1 >a &&
591 - cat old_a >>a &&
592 - rm old_a &&
593 - git add -u &&
594 - git commit -m "Merge commit C^0 into HEAD" &&
595 - git tag D &&
596 -
597 - git checkout C^0 &&
598 - git merge --no-commit -s ours B^0 &&
599 - git checkout B -- b &&
600 - echo 8 >>a &&
601 - git add -u &&
602 - git commit -m "Merge commit B^0 into HEAD" &&
603 - git tag E
607 +test_expect_success 'setup criss-cross + rename/rename/add-source + modify/modify' '
608 + test_create_repo rename-rename-add-source &&
609 + (
610 + cd rename-rename-add-source &&
611 +
612 + printf "lots\nof\nwords\nand\ncontent\n" >a &&
613 + git add a &&
614 + git commit -m A &&
615 + git tag A &&
616 +
617 + git checkout -b B A &&
618 + git mv a b &&
619 + git commit -m B &&
620 +
621 + git checkout -b C A &&
622 + git mv a c &&
623 + printf "2\n3\n4\n5\n6\n7\n" >a &&
624 + git add a &&
625 + git commit -m C &&
626 +
627 + git checkout B^0 &&
628 + git merge --no-commit -s ours C^0 &&
629 + git checkout C -- a c &&
630 + mv a old_a &&
631 + echo 1 >a &&
632 + cat old_a >>a &&
633 + rm old_a &&
634 + git add -u &&
635 + git commit -m "Merge commit C^0 into HEAD" &&
636 + git tag D &&
637 +
638 + git checkout C^0 &&
639 + git merge --no-commit -s ours B^0 &&
640 + git checkout B -- b &&
641 + echo 8 >>a &&
642 + git add -u &&
643 + git commit -m "Merge commit B^0 into HEAD" &&
644 + git tag E
645 + )
646 '
647
648 test_expect_failure 'detect rename/rename/add-source for virtual merge-base' '
607 - git checkout D^0 &&
649 + (
650 + cd rename-rename-add-source &&
651 +
652 + git checkout D^0 &&
653
609 - git merge -s recursive E^0 &&
654 + git merge -s recursive E^0 &&
655
611 - test 3 -eq $(git ls-files -s | wc -l) &&
612 - test 0 -eq $(git ls-files -u | wc -l) &&
613 - test 0 -eq $(git ls-files -o | wc -l) &&
656 + test 3 -eq $(git ls-files -s | wc -l) &&
657 + test 0 -eq $(git ls-files -u | wc -l) &&
658 + test 0 -eq $(git ls-files -o | wc -l) &&
659
615 - test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
616 - test $(git rev-parse HEAD:c) = $(git rev-parse A:a) &&
617 - test "$(cat a)" = "$(printf "1\n2\n3\n4\n5\n6\n7\n8\n")"
660 + test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
661 + test $(git rev-parse HEAD:c) = $(git rev-parse A:a) &&
662 + test "$(cat a)" = "$(printf "1\n2\n3\n4\n5\n6\n7\n8\n")"
663 + )
664 '
665
666 #
@@ -638,52 +684,56 @@ test_expect_failure 'detect rename/rename/add-source for virtual merge-base' '
684 # base of B & C needs to not delete B:c for that to work, though...
685
686 test_expect_success 'setup criss-cross+rename/rename/add-dest + simple modify' '
641 - git rm -rf . &&
642 - git clean -fdqx &&
643 - rm -rf .git &&
644 - git init &&
645 -
646 - >a &&
647 - git add a &&
648 - git commit -m A &&
649 - git tag A &&
650 -
651 - git checkout -b B A &&
652 - git mv a b &&
653 - printf "1\n2\n3\n4\n5\n6\n7\n" >c &&
654 - git add c &&
655 - git commit -m B &&
656 -
657 - git checkout -b C A &&
658 - git mv a c &&
659 - git commit -m C &&
660 -
661 - git checkout B^0 &&
662 - git merge --no-commit -s ours C^0 &&
663 - git mv b a &&
664 - git commit -m "D is like B but renames b back to a" &&
665 - git tag D &&
666 -
667 - git checkout B^0 &&
668 - git merge --no-commit -s ours C^0 &&
669 - git mv b a &&
670 - echo 8 >>c &&
671 - git add c &&
672 - git commit -m "E like D but has mod in c" &&
673 - git tag E
687 + test_create_repo rename-rename-add-dest &&
688 + (
689 + cd rename-rename-add-dest &&
690 +
691 + >a &&
692 + git add a &&
693 + git commit -m A &&
694 + git tag A &&
695 +
696 + git checkout -b B A &&
697 + git mv a b &&
698 + printf "1\n2\n3\n4\n5\n6\n7\n" >c &&
699 + git add c &&
700 + git commit -m B &&
701 +
702 + git checkout -b C A &&
703 + git mv a c &&
704 + git commit -m C &&
705 +
706 + git checkout B^0 &&
707 + git merge --no-commit -s ours C^0 &&
708 + git mv b a &&
709 + git commit -m "D is like B but renames b back to a" &&
710 + git tag D &&
711 +
712 + git checkout B^0 &&
713 + git merge --no-commit -s ours C^0 &&
714 + git mv b a &&
715 + echo 8 >>c &&
716 + git add c &&
717 + git commit -m "E like D but has mod in c" &&
718 + git tag E
719 + )
720 '
721
722 test_expect_success 'virtual merge base handles rename/rename(1to2)/add-dest' '
677 - git checkout D^0 &&
723 + (
724 + cd rename-rename-add-dest &&
725 +
726 + git checkout D^0 &&
727
679 - git merge -s recursive E^0 &&
728 + git merge -s recursive E^0 &&
729
681 - test 2 -eq $(git ls-files -s | wc -l) &&
682 - test 0 -eq $(git ls-files -u | wc -l) &&
683 - test 0 -eq $(git ls-files -o | wc -l) &&
730 + test 2 -eq $(git ls-files -s | wc -l) &&
731 + test 0 -eq $(git ls-files -u | wc -l) &&
732 + test 0 -eq $(git ls-files -o | wc -l) &&
733
685 - test $(git rev-parse HEAD:a) = $(git rev-parse A:a) &&
686 - test $(git rev-parse HEAD:c) = $(git rev-parse E:c)
734 + test $(git rev-parse HEAD:a) = $(git rev-parse A:a) &&
735 + test $(git rev-parse HEAD:c) = $(git rev-parse E:c)
736 + )
737 '
738
739 test_done
t/t6042-merge-rename-corner-cases.sh
+474 -413
@@ -6,31 +6,40 @@ test_description="recursive merge corner cases w/ renames but not criss-crosses"
6 . ./test-lib.sh
7
8 test_expect_success 'setup rename/delete + untracked file' '
9 - echo "A pretty inscription" >ring &&
10 - git add ring &&
11 - test_tick &&
12 - git commit -m beginning &&
13 -
14 - git branch people &&
15 - git checkout -b rename-the-ring &&
16 - git mv ring one-ring-to-rule-them-all &&
17 - test_tick &&
18 - git commit -m fullname &&
19 -
20 - git checkout people &&
21 - git rm ring &&
22 - echo gollum >owner &&
23 - git add owner &&
24 - test_tick &&
25 - git commit -m track-people-instead-of-objects &&
26 - echo "Myyy PRECIOUSSS" >ring
9 + test_create_repo rename-delete-untracked &&
10 + (
11 + cd rename-delete-untracked &&
12 +
13 + echo "A pretty inscription" >ring &&
14 + git add ring &&
15 + test_tick &&
16 + git commit -m beginning &&
17 +
18 + git branch people &&
19 + git checkout -b rename-the-ring &&
20 + git mv ring one-ring-to-rule-them-all &&
21 + test_tick &&
22 + git commit -m fullname &&
23 +
24 + git checkout people &&
25 + git rm ring &&
26 + echo gollum >owner &&
27 + git add owner &&
28 + test_tick &&
29 + git commit -m track-people-instead-of-objects &&
30 + echo "Myyy PRECIOUSSS" >ring
31 + )
32 '
33
34 test_expect_success "Does git preserve Gollum's precious artifact?" '
30 - test_must_fail git merge -s recursive rename-the-ring &&
35 + (
36 + cd rename-delete-untracked &&
37
32 - # Make sure git did not delete an untracked file
33 - test -f ring
38 + test_must_fail git merge -s recursive rename-the-ring &&
39 +
40 + # Make sure git did not delete an untracked file
41 + test -f ring
42 + )
43 '
44
45 # Testcase setup for rename/modify/add-source:
@@ -41,96 +50,116 @@ test_expect_success "Does git preserve Gollum's precious artifact?" '
50 # We should be able to merge B & C cleanly
51
52 test_expect_success 'setup rename/modify/add-source conflict' '
44 - git rm -rf . &&
45 - git clean -fdqx &&
46 - rm -rf .git &&
47 - git init &&
48 -
49 - printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
50 - git add a &&
51 - git commit -m A &&
52 - git tag A &&
53 -
54 - git checkout -b B A &&
55 - echo 8 >>a &&
56 - git add a &&
57 - git commit -m B &&
58 -
59 - git checkout -b C A &&
60 - git mv a b &&
61 - echo something completely different >a &&
62 - git add a &&
63 - git commit -m C
53 + test_create_repo rename-modify-add-source &&
54 + (
55 + cd rename-modify-add-source &&
56 +
57 + printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
58 + git add a &&
59 + git commit -m A &&
60 + git tag A &&
61 +
62 + git checkout -b B A &&
63 + echo 8 >>a &&
64 + git add a &&
65 + git commit -m B &&
66 +
67 + git checkout -b C A &&
68 + git mv a b &&
69 + echo something completely different >a &&
70 + git add a &&
71 + git commit -m C
72 + )
73 '
74
75 test_expect_failure 'rename/modify/add-source conflict resolvable' '
67 - git checkout B^0 &&
76 + (
77 + cd rename-modify-add-source &&
78 +
79 + git checkout B^0 &&
80
69 - git merge -s recursive C^0 &&
81 + git merge -s recursive C^0 &&
82
71 - test $(git rev-parse B:a) = $(git rev-parse b) &&
72 - test $(git rev-parse C:a) = $(git rev-parse a)
83 + test $(git rev-parse B:a) = $(git rev-parse b) &&
84 + test $(git rev-parse C:a) = $(git rev-parse a)
85 + )
86 '
87
88 test_expect_success 'setup resolvable conflict missed if rename missed' '
76 - git rm -rf . &&
77 - git clean -fdqx &&
78 - rm -rf .git &&
79 - git init &&
80 -
81 - printf "1\n2\n3\n4\n5\n" >a &&
82 - echo foo >b &&
83 - git add a b &&
84 - git commit -m A &&
85 - git tag A &&
86 -
87 - git checkout -b B A &&
88 - git mv a c &&
89 - echo "Completely different content" >a &&
90 - git add a &&
91 - git commit -m B &&
92 -
93 - git checkout -b C A &&
94 - echo 6 >>a &&
95 - git add a &&
96 - git commit -m C
89 + test_create_repo break-detection-1 &&
90 + (
91 + cd break-detection-1 &&
92 +
93 + printf "1\n2\n3\n4\n5\n" >a &&
94 + echo foo >b &&
95 + git add a b &&
96 + git commit -m A &&
97 + git tag A &&
98 +
99 + git checkout -b B A &&
100 + git mv a c &&
101 + echo "Completely different content" >a &&
102 + git add a &&
103 + git commit -m B &&
104 +
105 + git checkout -b C A &&
106 + echo 6 >>a &&
107 + git add a &&
108 + git commit -m C
109 + )
110 '
111
112 test_expect_failure 'conflict caused if rename not detected' '
100 - git checkout -q C^0 &&
101 - git merge -s recursive B^0 &&
113 + (
114 + cd break-detection-1 &&
115 +
116 + git checkout -q C^0 &&
117 + git merge -s recursive B^0 &&
118
103 - test 3 -eq $(git ls-files -s | wc -l) &&
104 - test 0 -eq $(git ls-files -u | wc -l) &&
105 - test 0 -eq $(git ls-files -o | wc -l) &&
119 + test 3 -eq $(git ls-files -s | wc -l) &&
120 + test 0 -eq $(git ls-files -u | wc -l) &&
121 + test 0 -eq $(git ls-files -o | wc -l) &&
122
107 - test_line_count = 6 c &&
108 - test $(git rev-parse HEAD:a) = $(git rev-parse B:a) &&
109 - test $(git rev-parse HEAD:b) = $(git rev-parse A:b)
123 + test_line_count = 6 c &&
124 + test $(git rev-parse HEAD:a) = $(git rev-parse B:a) &&
125 + test $(git rev-parse HEAD:b) = $(git rev-parse A:b)
126 + )
127 '
128
129 test_expect_success 'setup conflict resolved wrong if rename missed' '
113 - git reset --hard &&
114 - git clean -f &&
115 -
116 - git checkout -b D A &&
117 - echo 7 >>a &&
118 - git add a &&
119 - git mv a c &&
120 - echo "Completely different content" >a &&
121 - git add a &&
122 - git commit -m D &&
123 -
124 - git checkout -b E A &&
125 - git rm a &&
126 - echo "Completely different content" >>a &&
127 - git add a &&
128 - git commit -m E
130 + test_create_repo break-detection-2 &&
131 + (
132 + cd break-detection-2 &&
133 +
134 + printf "1\n2\n3\n4\n5\n" >a &&
135 + echo foo >b &&
136 + git add a b &&
137 + git commit -m A &&
138 + git tag A &&
139 +
140 + git checkout -b D A &&
141 + echo 7 >>a &&
142 + git add a &&
143 + git mv a c &&
144 + echo "Completely different content" >a &&
145 + git add a &&
146 + git commit -m D &&
147 +
148 + git checkout -b E A &&
149 + git rm a &&
150 + echo "Completely different content" >>a &&
151 + git add a &&
152 + git commit -m E
153 + )
154 '
155
156 test_expect_failure 'missed conflict if rename not detected' '
132 - git checkout -q E^0 &&
133 - test_must_fail git merge -s recursive D^0
157 + (
158 + cd break-detection-2 &&
159 +
160 + git checkout -q E^0 &&
161 + test_must_fail git merge -s recursive D^0
162 + )
163 '
164
165 # Tests for undetected rename/add-source causing a file to erroneously be
@@ -145,198 +174,210 @@ test_expect_failure 'missed conflict if rename not detected' '
174 # Commit C: rename a->b, add unrelated a
175
176 test_expect_success 'setup undetected rename/add-source causes data loss' '
148 - git rm -rf . &&
149 - git clean -fdqx &&
150 - rm -rf .git &&
151 - git init &&
152 -
153 - printf "1\n2\n3\n4\n5\n" >a &&
154 - git add a &&
155 - git commit -m A &&
156 - git tag A &&
157 -
158 - git checkout -b B A &&
159 - git mv a b &&
160 - git commit -m B &&
161 -
162 - git checkout -b C A &&
163 - git mv a b &&
164 - echo foobar >a &&
165 - git add a &&
166 - git commit -m C
177 + test_create_repo break-detection-3 &&
178 + (
179 + cd break-detection-3 &&
180 +
181 + printf "1\n2\n3\n4\n5\n" >a &&
182 + git add a &&
183 + git commit -m A &&
184 + git tag A &&
185 +
186 + git checkout -b B A &&
187 + git mv a b &&
188 + git commit -m B &&
189 +
190 + git checkout -b C A &&
191 + git mv a b &&
192 + echo foobar >a &&
193 + git add a &&
194 + git commit -m C
195 + )
196 '
197
198 test_expect_failure 'detect rename/add-source and preserve all data' '
170 - git checkout B^0 &&
199 + (
200 + cd break-detection-3 &&
201 +
202 + git checkout B^0 &&
203
172 - git merge -s recursive C^0 &&
204 + git merge -s recursive C^0 &&
205
174 - test 2 -eq $(git ls-files -s | wc -l) &&
175 - test 2 -eq $(git ls-files -u | wc -l) &&
176 - test 0 -eq $(git ls-files -o | wc -l) &&
206 + test 2 -eq $(git ls-files -s | wc -l) &&
207 + test 2 -eq $(git ls-files -u | wc -l) &&
208 + test 0 -eq $(git ls-files -o | wc -l) &&
209
178 - test -f a &&
179 - test -f b &&
210 + test -f a &&
211 + test -f b &&
212
181 - test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
182 - test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
213 + test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
214 + test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
215 + )
216 '
217
218 test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
186 - git checkout C^0 &&
219 + (
220 + cd break-detection-3 &&
221
188 - git merge -s recursive B^0 &&
222 + git checkout C^0 &&
223
190 - test 2 -eq $(git ls-files -s | wc -l) &&
191 - test 2 -eq $(git ls-files -u | wc -l) &&
192 - test 0 -eq $(git ls-files -o | wc -l) &&
224 + git merge -s recursive B^0 &&
225
194 - test -f a &&
195 - test -f b &&
226 + test 2 -eq $(git ls-files -s | wc -l) &&
227 + test 2 -eq $(git ls-files -u | wc -l) &&
228 + test 0 -eq $(git ls-files -o | wc -l) &&
229
197 - test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
198 - test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
230 + test -f a &&
231 + test -f b &&
232 +
233 + test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
234 + test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
235 + )
236 '
237
238 test_expect_success 'setup content merge + rename/directory conflict' '
202 - git rm -rf . &&
203 - git clean -fdqx &&
204 - rm -rf .git &&
205 - git init &&
206 -
207 - printf "1\n2\n3\n4\n5\n6\n" >file &&
208 - git add file &&
209 - test_tick &&
210 - git commit -m base &&
211 - git tag base &&
212 -
213 - git checkout -b right &&
214 - echo 7 >>file &&
215 - mkdir newfile &&
216 - echo junk >newfile/realfile &&
217 - git add file newfile/realfile &&
218 - test_tick &&
219 - git commit -m right &&
220 -
221 - git checkout -b left-conflict base &&
222 - echo 8 >>file &&
223 - git add file &&
224 - git mv file newfile &&
225 - test_tick &&
226 - git commit -m left &&
227 -
228 - git checkout -b left-clean base &&
229 - echo 0 >newfile &&
230 - cat file >>newfile &&
231 - git add newfile &&
232 - git rm file &&
233 - test_tick &&
234 - git commit -m left
239 + test_create_repo rename-directory-1 &&
240 + (
241 + cd rename-directory-1 &&
242 +
243 + printf "1\n2\n3\n4\n5\n6\n" >file &&
244 + git add file &&
245 + test_tick &&
246 + git commit -m base &&
247 + git tag base &&
248 +
249 + git checkout -b right &&
250 + echo 7 >>file &&
251 + mkdir newfile &&
252 + echo junk >newfile/realfile &&
253 + git add file newfile/realfile &&
254 + test_tick &&
255 + git commit -m right &&
256 +
257 + git checkout -b left-conflict base &&
258 + echo 8 >>file &&
259 + git add file &&
260 + git mv file newfile &&
261 + test_tick &&
262 + git commit -m left &&
263 +
264 + git checkout -b left-clean base &&
265 + echo 0 >newfile &&
266 + cat file >>newfile &&
267 + git add newfile &&
268 + git rm file &&
269 + test_tick &&
270 + git commit -m left
271 + )
272 '
273
274 test_expect_success 'rename/directory conflict + clean content merge' '
238 - git reset --hard &&
239 - git reset --hard &&
240 - git clean -fdqx &&
275 + (
276 + cd rename-directory-1 &&
277
242 - git checkout left-clean^0 &&
278 + git checkout left-clean^0 &&
279
244 - test_must_fail git merge -s recursive right^0 &&
280 + test_must_fail git merge -s recursive right^0 &&
281
246 - test 2 -eq $(git ls-files -s | wc -l) &&
247 - test 1 -eq $(git ls-files -u | wc -l) &&
248 - test 1 -eq $(git ls-files -o | wc -l) &&
282 + test 2 -eq $(git ls-files -s | wc -l) &&
283 + test 1 -eq $(git ls-files -u | wc -l) &&
284 + test 1 -eq $(git ls-files -o | wc -l) &&
285
250 - echo 0 >expect &&
251 - git cat-file -p base:file >>expect &&
252 - echo 7 >>expect &&
253 - test_cmp expect newfile~HEAD &&
286 + echo 0 >expect &&
287 + git cat-file -p base:file >>expect &&
288 + echo 7 >>expect &&
289 + test_cmp expect newfile~HEAD &&
290
255 - test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
291 + test $(git rev-parse :2:newfile) = $(git hash-object expect) &&
292
257 - test -f newfile/realfile &&
258 - test -f newfile~HEAD
293 + test -f newfile/realfile &&
294 + test -f newfile~HEAD
295 + )
296 '
297
298 test_expect_success 'rename/directory conflict + content merge conflict' '
262 - git reset --hard &&
263 - git reset --hard &&
264 - git clean -fdqx &&
265 -
266 - git checkout left-conflict^0 &&
267 -
268 - test_must_fail git merge -s recursive right^0 &&
269 -
270 - test 4 -eq $(git ls-files -s | wc -l) &&
271 - test 3 -eq $(git ls-files -u | wc -l) &&
272 - test 1 -eq $(git ls-files -o | wc -l) &&
273 -
274 - git cat-file -p left-conflict:newfile >left &&
275 - git cat-file -p base:file >base &&
276 - git cat-file -p right:file >right &&
277 - test_must_fail git merge-file \
278 - -L "HEAD:newfile" \
279 - -L "" \
280 - -L "right^0:file" \
281 - left base right &&
282 - test_cmp left newfile~HEAD &&
283 -
284 - test $(git rev-parse :1:newfile) = $(git rev-parse base:file) &&
285 - test $(git rev-parse :2:newfile) = $(git rev-parse left-conflict:newfile) &&
286 - test $(git rev-parse :3:newfile) = $(git rev-parse right:file) &&
287 -
288 - test -f newfile/realfile &&
289 - test -f newfile~HEAD
299 + (
300 + cd rename-directory-1 &&
301 +
302 + git reset --hard &&
303 + git reset --hard &&
304 + git clean -fdqx &&
305 +
306 + git checkout left-conflict^0 &&
307 +
308 + test_must_fail git merge -s recursive right^0 &&
309 +
310 + test 4 -eq $(git ls-files -s | wc -l) &&
311 + test 3 -eq $(git ls-files -u | wc -l) &&
312 + test 1 -eq $(git ls-files -o | wc -l) &&
313 +
314 + git cat-file -p left-conflict:newfile >left &&
315 + git cat-file -p base:file >base &&
316 + git cat-file -p right:file >right &&
317 + test_must_fail git merge-file \
318 + -L "HEAD:newfile" \
319 + -L "" \
320 + -L "right^0:file" \
321 + left base right &&
322 + test_cmp left newfile~HEAD &&
323 +
324 + test $(git rev-parse :1:newfile) = $(git rev-parse base:file) &&
325 + test $(git rev-parse :2:newfile) = $(git rev-parse left-conflict:newfile) &&
326 + test $(git rev-parse :3:newfile) = $(git rev-parse right:file) &&
327 +
328 + test -f newfile/realfile &&
329 + test -f newfile~HEAD
330 + )
331 '
332
333 test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' '
293 - git reset --hard &&
294 - git rm -rf . &&
295 - git clean -fdqx &&
296 - rm -rf .git &&
297 - git init &&
298 -
299 - mkdir sub &&
300 - printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
301 - git add sub/file &&
302 - test_tick &&
303 - git commit -m base &&
304 - git tag base &&
305 -
306 - git checkout -b right &&
307 - echo 7 >>sub/file &&
308 - git add sub/file &&
309 - test_tick &&
310 - git commit -m right &&
311 -
312 - git checkout -b left base &&
313 - echo 0 >newfile &&
314 - cat sub/file >>newfile &&
315 - git rm sub/file &&
316 - mv newfile sub &&
317 - git add sub &&
318 - test_tick &&
319 - git commit -m left
334 + test_create_repo rename-directory-2 &&
335 + (
336 + cd rename-directory-2 &&
337 +
338 + mkdir sub &&
339 + printf "1\n2\n3\n4\n5\n6\n" >sub/file &&
340 + git add sub/file &&
341 + test_tick &&
342 + git commit -m base &&
343 + git tag base &&
344 +
345 + git checkout -b right &&
346 + echo 7 >>sub/file &&
347 + git add sub/file &&
348 + test_tick &&
349 + git commit -m right &&
350 +
351 + git checkout -b left base &&
352 + echo 0 >newfile &&
353 + cat sub/file >>newfile &&
354 + git rm sub/file &&
355 + mv newfile sub &&
356 + git add sub &&
357 + test_tick &&
358 + git commit -m left
359 + )
360 '
361
362 test_expect_success 'disappearing dir in rename/directory conflict handled' '
323 - git reset --hard &&
324 - git clean -fdqx &&
363 + (
364 + cd rename-directory-2 &&
365
326 - git checkout left^0 &&
366 + git checkout left^0 &&
367
328 - git merge -s recursive right^0 &&
368 + git merge -s recursive right^0 &&
369
330 - test 1 -eq $(git ls-files -s | wc -l) &&
331 - test 0 -eq $(git ls-files -u | wc -l) &&
332 - test 0 -eq $(git ls-files -o | wc -l) &&
370 + test 1 -eq $(git ls-files -s | wc -l) &&
371 + test 0 -eq $(git ls-files -u | wc -l) &&
372 + test 0 -eq $(git ls-files -o | wc -l) &&
373
334 - echo 0 >expect &&
335 - git cat-file -p base:sub/file >>expect &&
336 - echo 7 >>expect &&
337 - test_cmp expect sub &&
374 + echo 0 >expect &&
375 + git cat-file -p base:sub/file >>expect &&
376 + echo 7 >>expect &&
377 + test_cmp expect sub &&
378
339 - test -f sub
379 + test -f sub
380 + )
381 '
382
383 # Test for all kinds of things that can go wrong with rename/rename (2to1):
@@ -352,48 +393,52 @@ test_expect_success 'disappearing dir in rename/directory conflict handled' '
393 # * Nothing else should be present. Is anything?
394
395 test_expect_success 'setup rename/rename (2to1) + modify/modify' '
355 - git rm -rf . &&
356 - git clean -fdqx &&
357 - rm -rf .git &&
358 - git init &&
359 -
360 - printf "1\n2\n3\n4\n5\n" >a &&
361 - printf "5\n4\n3\n2\n1\n" >b &&
362 - git add a b &&
363 - git commit -m A &&
364 - git tag A &&
365 -
366 - git checkout -b B A &&
367 - git mv a c &&
368 - echo 0 >>b &&
369 - git add b &&
370 - git commit -m B &&
371 -
372 - git checkout -b C A &&
373 - git mv b c &&
374 - echo 6 >>a &&
375 - git add a &&
376 - git commit -m C
396 + test_create_repo rename-rename-2to1 &&
397 + (
398 + cd rename-rename-2to1 &&
399 +
400 + printf "1\n2\n3\n4\n5\n" >a &&
401 + printf "5\n4\n3\n2\n1\n" >b &&
402 + git add a b &&
403 + git commit -m A &&
404 + git tag A &&
405 +
406 + git checkout -b B A &&
407 + git mv a c &&
408 + echo 0 >>b &&
409 + git add b &&
410 + git commit -m B &&
411 +
412 + git checkout -b C A &&
413 + git mv b c &&
414 + echo 6 >>a &&
415 + git add a &&
416 + git commit -m C
417 + )
418 '
419
420 test_expect_success 'handle rename/rename (2to1) conflict correctly' '
380 - git checkout B^0 &&
421 + (
422 + cd rename-rename-2to1 &&
423 +
424 + git checkout B^0 &&
425
382 - test_must_fail git merge -s recursive C^0 >out &&
383 - test_i18ngrep "CONFLICT (rename/rename)" out &&
426 + test_must_fail git merge -s recursive C^0 >out &&
427 + test_i18ngrep "CONFLICT (rename/rename)" out &&
428
385 - test 2 -eq $(git ls-files -s | wc -l) &&
386 - test 2 -eq $(git ls-files -u | wc -l) &&
387 - test 2 -eq $(git ls-files -u c | wc -l) &&
388 - test 3 -eq $(git ls-files -o | wc -l) &&
429 + test 2 -eq $(git ls-files -s | wc -l) &&
430 + test 2 -eq $(git ls-files -u | wc -l) &&
431 + test 2 -eq $(git ls-files -u c | wc -l) &&
432 + test 3 -eq $(git ls-files -o | wc -l) &&
433
390 - test ! -f a &&
391 - test ! -f b &&
392 - test -f c~HEAD &&
393 - test -f c~C^0 &&
434 + test ! -f a &&
435 + test ! -f b &&
436 + test -f c~HEAD &&
437 + test -f c~C^0 &&
438
395 - test $(git hash-object c~HEAD) = $(git rev-parse C:a) &&
396 - test $(git hash-object c~C^0) = $(git rev-parse B:b)
439 + test $(git hash-object c~HEAD) = $(git rev-parse C:a) &&
440 + test $(git hash-object c~C^0) = $(git rev-parse B:b)
441 + )
442 '
443
444 # Testcase setup for simple rename/rename (1to2) conflict:
@@ -401,44 +446,48 @@ test_expect_success 'handle rename/rename (2to1) conflict correctly' '
446 # Commit B: rename a->b
447 # Commit C: rename a->c
448 test_expect_success 'setup simple rename/rename (1to2) conflict' '
404 - git rm -rf . &&
405 - git clean -fdqx &&
406 - rm -rf .git &&
407 - git init &&
408 -
409 - echo stuff >a &&
410 - git add a &&
411 - test_tick &&
412 - git commit -m A &&
413 - git tag A &&
414 -
415 - git checkout -b B A &&
416 - git mv a b &&
417 - test_tick &&
418 - git commit -m B &&
419 -
420 - git checkout -b C A &&
421 - git mv a c &&
422 - test_tick &&
423 - git commit -m C
449 + test_create_repo rename-rename-1to2 &&
450 + (
451 + cd rename-rename-1to2 &&
452 +
453 + echo stuff >a &&
454 + git add a &&
455 + test_tick &&
456 + git commit -m A &&
457 + git tag A &&
458 +
459 + git checkout -b B A &&
460 + git mv a b &&
461 + test_tick &&
462 + git commit -m B &&
463 +
464 + git checkout -b C A &&
465 + git mv a c &&
466 + test_tick &&
467 + git commit -m C
468 + )
469 '
470
471 test_expect_success 'merge has correct working tree contents' '
427 - git checkout C^0 &&
472 + (
473 + cd rename-rename-1to2 &&
474 +
475 + git checkout C^0 &&
476
429 - test_must_fail git merge -s recursive B^0 &&
477 + test_must_fail git merge -s recursive B^0 &&
478
431 - test 3 -eq $(git ls-files -s | wc -l) &&
432 - test 3 -eq $(git ls-files -u | wc -l) &&
433 - test 0 -eq $(git ls-files -o | wc -l) &&
479 + test 3 -eq $(git ls-files -s | wc -l) &&
480 + test 3 -eq $(git ls-files -u | wc -l) &&
481 + test 0 -eq $(git ls-files -o | wc -l) &&
482
435 - test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
436 - test $(git rev-parse :3:b) = $(git rev-parse A:a) &&
437 - test $(git rev-parse :2:c) = $(git rev-parse A:a) &&
483 + test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
484 + test $(git rev-parse :3:b) = $(git rev-parse A:a) &&
485 + test $(git rev-parse :2:c) = $(git rev-parse A:a) &&
486
439 - test ! -f a &&
440 - test $(git hash-object b) = $(git rev-parse A:a) &&
441 - test $(git hash-object c) = $(git rev-parse A:a)
487 + test ! -f a &&
488 + test $(git hash-object b) = $(git rev-parse A:a) &&
489 + test $(git hash-object c) = $(git rev-parse A:a)
490 + )
491 '
492
493 # Testcase setup for rename/rename(1to2)/add-source conflict:
@@ -449,130 +498,142 @@ test_expect_success 'merge has correct working tree contents' '
498 # Merging of B & C should NOT be clean; there's a rename/rename conflict
499
500 test_expect_success 'setup rename/rename(1to2)/add-source conflict' '
452 - git rm -rf . &&
453 - git clean -fdqx &&
454 - rm -rf .git &&
455 - git init &&
456 -
457 - printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
458 - git add a &&
459 - git commit -m A &&
460 - git tag A &&
461 -
462 - git checkout -b B A &&
463 - git mv a b &&
464 - git commit -m B &&
465 -
466 - git checkout -b C A &&
467 - git mv a c &&
468 - echo something completely different >a &&
469 - git add a &&
470 - git commit -m C
501 + test_create_repo rename-rename-1to2-add-source-1 &&
502 + (
503 + cd rename-rename-1to2-add-source-1 &&
504 +
505 + printf "1\n2\n3\n4\n5\n6\n7\n" >a &&
506 + git add a &&
507 + git commit -m A &&
508 + git tag A &&
509 +
510 + git checkout -b B A &&
511 + git mv a b &&
512 + git commit -m B &&
513 +
514 + git checkout -b C A &&
515 + git mv a c &&
516 + echo something completely different >a &&
517 + git add a &&
518 + git commit -m C
519 + )
520 '
521
522 test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' '
474 - git checkout B^0 &&
523 + (
524 + cd rename-rename-1to2-add-source-1 &&
525
476 - test_must_fail git merge -s recursive C^0 &&
526 + git checkout B^0 &&
527
478 - test 4 -eq $(git ls-files -s | wc -l) &&
479 - test 0 -eq $(git ls-files -o | wc -l) &&
528 + test_must_fail git merge -s recursive C^0 &&
529
481 - test $(git rev-parse 3:a) = $(git rev-parse C:a) &&
482 - test $(git rev-parse 1:a) = $(git rev-parse A:a) &&
483 - test $(git rev-parse 2:b) = $(git rev-parse B:b) &&
484 - test $(git rev-parse 3:c) = $(git rev-parse C:c) &&
530 + test 4 -eq $(git ls-files -s | wc -l) &&
531 + test 0 -eq $(git ls-files -o | wc -l) &&
532
486 - test -f a &&
487 - test -f b &&
488 - test -f c
533 + test $(git rev-parse 3:a) = $(git rev-parse C:a) &&
534 + test $(git rev-parse 1:a) = $(git rev-parse A:a) &&
535 + test $(git rev-parse 2:b) = $(git rev-parse B:b) &&
536 + test $(git rev-parse 3:c) = $(git rev-parse C:c) &&
537 +
538 + test -f a &&
539 + test -f b &&
540 + test -f c
541 + )
542 '
543
544 test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' '
492 - git rm -rf . &&
493 - git clean -fdqx &&
494 - rm -rf .git &&
495 - git init &&
496 -
497 - >a &&
498 - git add a &&
499 - test_tick &&
500 - git commit -m base &&
501 - git tag A &&
502 -
503 - git checkout -b B A &&
504 - git mv a b &&
505 - test_tick &&
506 - git commit -m one &&
507 -
508 - git checkout -b C A &&
509 - git mv a b &&
510 - echo important-info >a &&
511 - git add a &&
512 - test_tick &&
513 - git commit -m two
545 + test_create_repo rename-rename-1to2-add-source-2 &&
546 + (
547 + cd rename-rename-1to2-add-source-2 &&
548 +
549 + >a &&
550 + git add a &&
551 + test_tick &&
552 + git commit -m base &&
553 + git tag A &&
554 +
555 + git checkout -b B A &&
556 + git mv a b &&
557 + test_tick &&
558 + git commit -m one &&
559 +
560 + git checkout -b C A &&
561 + git mv a b &&
562 + echo important-info >a &&
563 + git add a &&
564 + test_tick &&
565 + git commit -m two
566 + )
567 '
568
569 test_expect_failure 'rename/rename/add-source still tracks new a file' '
517 - git checkout C^0 &&
518 - git merge -s recursive B^0 &&
570 + (
571 + cd rename-rename-1to2-add-source-2 &&
572 +
573 + git checkout C^0 &&
574 + git merge -s recursive B^0 &&
575
520 - test 2 -eq $(git ls-files -s | wc -l) &&
521 - test 0 -eq $(git ls-files -o | wc -l) &&
576 + test 2 -eq $(git ls-files -s | wc -l) &&
577 + test 0 -eq $(git ls-files -o | wc -l) &&
578
523 - test $(git rev-parse HEAD:a) = $(git rev-parse C:a) &&
524 - test $(git rev-parse HEAD:b) = $(git rev-parse A:a)
579 + test $(git rev-parse HEAD:a) = $(git rev-parse C:a) &&
580 + test $(git rev-parse HEAD:b) = $(git rev-parse A:a)
581 + )
582 '
583
584 test_expect_success 'setup rename/rename(1to2)/add-dest conflict' '
528 - git rm -rf . &&
529 - git clean -fdqx &&
530 - rm -rf .git &&
531 - git init &&
532 -
533 - echo stuff >a &&
534 - git add a &&
535 - test_tick &&
536 - git commit -m base &&
537 - git tag A &&
538 -
539 - git checkout -b B A &&
540 - git mv a b &&
541 - echo precious-data >c &&
542 - git add c &&
543 - test_tick &&
544 - git commit -m one &&
545 -
546 - git checkout -b C A &&
547 - git mv a c &&
548 - echo important-info >b &&
549 - git add b &&
550 - test_tick &&
551 - git commit -m two
585 + test_create_repo rename-rename-1to2-add-dest &&
586 + (
587 + cd rename-rename-1to2-add-dest &&
588 +
589 + echo stuff >a &&
590 + git add a &&
591 + test_tick &&
592 + git commit -m base &&
593 + git tag A &&
594 +
595 + git checkout -b B A &&
596 + git mv a b &&
597 + echo precious-data >c &&
598 + git add c &&
599 + test_tick &&
600 + git commit -m one &&
601 +
602 + git checkout -b C A &&
603 + git mv a c &&
604 + echo important-info >b &&
605 + git add b &&
606 + test_tick &&
607 + git commit -m two
608 + )
609 '
610
611 test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' '
555 - git checkout C^0 &&
556 - test_must_fail git merge -s recursive B^0 &&
557 -
558 - test 5 -eq $(git ls-files -s | wc -l) &&
559 - test 2 -eq $(git ls-files -u b | wc -l) &&
560 - test 2 -eq $(git ls-files -u c | wc -l) &&
561 - test 4 -eq $(git ls-files -o | wc -l) &&
562 -
563 - test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
564 - test $(git rev-parse :2:b) = $(git rev-parse C:b) &&
565 - test $(git rev-parse :3:b) = $(git rev-parse B:b) &&
566 - test $(git rev-parse :2:c) = $(git rev-parse C:c) &&
567 - test $(git rev-parse :3:c) = $(git rev-parse B:c) &&
568 -
569 - test $(git hash-object c~HEAD) = $(git rev-parse C:c) &&
570 - test $(git hash-object c~B\^0) = $(git rev-parse B:c) &&
571 - test $(git hash-object b~HEAD) = $(git rev-parse C:b) &&
572 - test $(git hash-object b~B\^0) = $(git rev-parse B:b) &&
573 -
574 - test ! -f b &&
575 - test ! -f c
612 + (
613 + cd rename-rename-1to2-add-dest &&
614 +
615 + git checkout C^0 &&
616 + test_must_fail git merge -s recursive B^0 &&
617 +
618 + test 5 -eq $(git ls-files -s | wc -l) &&
619 + test 2 -eq $(git ls-files -u b | wc -l) &&
620 + test 2 -eq $(git ls-files -u c | wc -l) &&
621 + test 4 -eq $(git ls-files -o | wc -l) &&
622 +
623 + test $(git rev-parse :1:a) = $(git rev-parse A:a) &&
624 + test $(git rev-parse :2:b) = $(git rev-parse C:b) &&
625 + test $(git rev-parse :3:b) = $(git rev-parse B:b) &&
626 + test $(git rev-parse :2:c) = $(git rev-parse C:c) &&
627 + test $(git rev-parse :3:c) = $(git rev-parse B:c) &&
628 +
629 + test $(git hash-object c~HEAD) = $(git rev-parse C:c) &&
630 + test $(git hash-object c~B\^0) = $(git rev-parse B:c) &&
631 + test $(git hash-object b~HEAD) = $(git rev-parse C:b) &&
632 + test $(git hash-object b~B\^0) = $(git rev-parse B:b) &&
633 +
634 + test ! -f b &&
635 + test ! -f c
636 + )
637 '
638
639 test_done