3 # Copyright (c) 2006 Johannes E. Schindelin
6 test_description='git rerere
12 ! [second] prefer first over second
19 - [second] prefer first over second
22 ++++++ [master] initial
27 test_expect_success 'setup' '
31 Whether '\''tis nobler in the mind to suffer
32 The slings and arrows of outrageous fortune,
33 Or to take arms against a sea of troubles,
34 And by opposing end them? To die: to sleep;
35 No more; and by a sleep to say we end
36 The heart-ache and the thousand natural shocks
37 That flesh is heir to, '\''tis a consummation
38 Devoutly to be wish'\''d.
43 git commit -q -a -m initial &&
49 To sleep: perchance to dream: ay, there'\''s the rub;
50 For in that sleep of death what dreams may come
51 When we have shuffled off this mortal coil,
52 Must give us pause: there'\''s the respect
53 That makes calamity of so long life;
56 git checkout -b first &&
58 git commit -q -a -m first &&
60 git checkout -b second master &&
62 sed -e "s/To die, t/To die! T/" -e "s/Some title/Some Title/" >a1 &&
63 echo "* END *" >>a1 &&
65 git commit -q -a -m second
68 test_expect_success 'nothing recorded without rerere' '
69 rm -rf .git/rr-cache &&
70 git config rerere.enabled false &&
71 test_must_fail git merge first &&
72 ! test -d .git/rr-cache
75 test_expect_success 'activate rerere, old style (conflicting merge)' '
77 mkdir .git/rr-cache &&
78 test_might_fail git config --unset rerere.enabled &&
79 test_must_fail git merge first &&
81 sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
82 rr=.git/rr-cache/$sha1 &&
83 grep "^=======\$" $rr/preimage &&
84 ! test -f $rr/postimage &&
85 ! test -f $rr/thisimage
88 test_expect_success 'rerere.enabled works, too' '
89 rm -rf .git/rr-cache &&
90 git config rerere.enabled true &&
92 test_must_fail git merge first &&
94 sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
95 rr=.git/rr-cache/$sha1 &&
96 grep ^=======$ $rr/preimage
99 test_expect_success 'set up rr-cache' '
100 rm -rf .git/rr-cache &&
101 git config rerere.enabled true &&
103 test_must_fail git merge first &&
104 sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
105 rr=.git/rr-cache/$sha1
108 test_expect_success 'rr-cache looks sane' '
109 # no postimage or thisimage yet
110 ! test -f $rr/postimage &&
111 ! test -f $rr/thisimage &&
113 # preimage has right number of lines
114 cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
119 test_expect_success 'rerere diff' '
120 git show first:a1 >a1 &&
121 cat >expect <<-\EOF &&
128 Whether '\''tis nobler in the mind to suffer
129 The slings and arrows of outrageous fortune,
131 The heart-ache and the thousand natural shocks
132 That flesh is heir to, '\''tis a consummation
133 Devoutly to be wish'\''d.
143 To sleep: perchance to dream: ay, there'\''s the rub;
144 For in that sleep of death what dreams may come
145 When we have shuffled off this mortal coil,
146 Must give us pause: there'\''s the respect
147 That makes calamity of so long life;
153 git rerere diff >out &&
157 test_expect_success 'rerere status' '
159 git rerere status >out &&
163 test_expect_success 'first postimage wins' '
164 git show first:a1 | sed "s/To die: t/To die! T/" >expect &&
166 git commit -q -a -m "prefer first over second" &&
167 test -f $rr/postimage &&
169 oldmtimepost=$(test-tool chmtime --get -60 $rr/postimage) &&
171 git checkout -b third master &&
172 git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
173 git commit -q -a -m third &&
175 test_must_fail git merge first &&
177 ! grep "^=======\$" a1 &&
181 test_expect_success 'rerere updates postimage timestamp' '
182 newmtimepost=$(test-tool chmtime --get $rr/postimage) &&
183 test $oldmtimepost -lt $newmtimepost
186 test_expect_success 'rerere clear' '
187 mv $rr/postimage .git/post-saved &&
188 echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
193 test_expect_success 'leftover directory' '
196 test_must_fail git merge first &&
200 test_expect_success 'missing preimage' '
203 cp .git/post-saved $rr/postimage &&
204 test_must_fail git merge first &&
208 test_expect_success 'set up for garbage collection tests' '
210 echo Hello >$rr/preimage &&
211 echo World >$rr/postimage &&
213 sha2=4000000000000000000000000000000000000000 &&
214 rr2=.git/rr-cache/$sha2 &&
216 echo Hello >$rr2/preimage &&
218 almost_15_days_ago=$((60-15*86400)) &&
219 just_over_15_days_ago=$((-1-15*86400)) &&
220 almost_60_days_ago=$((60-60*86400)) &&
221 just_over_60_days_ago=$((-1-60*86400)) &&
223 test-tool chmtime =$just_over_60_days_ago $rr/preimage &&
224 test-tool chmtime =$almost_60_days_ago $rr/postimage &&
225 test-tool chmtime =$almost_15_days_ago $rr2/preimage
228 test_expect_success 'gc preserves young or recently used records' '
230 test -f $rr/preimage &&
231 test -f $rr2/preimage
234 test_expect_success 'old records rest in peace' '
235 test-tool chmtime =$just_over_60_days_ago $rr/postimage &&
236 test-tool chmtime =$just_over_15_days_ago $rr2/preimage &&
238 ! test -f $rr/preimage &&
239 ! test -f $rr2/preimage
242 rerere_gc_custom_expiry_test () {
243 five_days="$1" right_now="$2"
244 test_expect_success "rerere gc with custom expiry ($five_days, $right_now)" '
245 rm -fr .git/rr-cache &&
246 rr=.git/rr-cache/$_z40 &&
251 two_days_ago=$((-2*86400)) &&
252 test-tool chmtime =$two_days_ago "$rr/preimage" &&
253 test-tool chmtime =$two_days_ago "$rr/postimage" &&
255 find .git/rr-cache -type f | sort >original &&
257 git -c "gc.rerereresolved=$five_days" \
258 -c "gc.rerereunresolved=$five_days" rerere gc &&
259 find .git/rr-cache -type f | sort >actual &&
260 test_cmp original actual &&
262 git -c "gc.rerereresolved=$five_days" \
263 -c "gc.rerereunresolved=$right_now" rerere gc &&
264 find .git/rr-cache -type f | sort >actual &&
265 test_cmp original actual &&
267 git -c "gc.rerereresolved=$right_now" \
268 -c "gc.rerereunresolved=$right_now" rerere gc &&
269 find .git/rr-cache -type f | sort >actual &&
271 test_cmp expect actual
275 rerere_gc_custom_expiry_test 5 0
277 rerere_gc_custom_expiry_test 5.days.ago now
279 test_expect_success 'setup: file2 added differently in two branches' '
282 git checkout -b fourth &&
286 git commit -m version1 &&
288 git checkout third &&
292 git commit -m version2 &&
294 test_must_fail git merge fourth &&
297 git commit -m resolution
300 test_expect_success 'resolution was recorded properly' '
301 echo Cello >expected &&
303 git reset --hard HEAD~2 &&
304 git checkout -b fifth &&
309 git commit -m version1 &&
311 git checkout third &&
315 git commit -m version2 &&
318 test_must_fail git merge fifth &&
319 test_cmp expected file3 &&
320 test_must_fail git update-index --refresh
323 test_expect_success 'rerere.autoupdate' '
324 git config rerere.autoupdate true &&
326 git checkout version2 &&
327 test_must_fail git merge fifth &&
328 git update-index --refresh
331 test_expect_success 'merge --rerere-autoupdate' '
332 test_might_fail git config --unset rerere.autoupdate &&
334 git checkout version2 &&
335 test_must_fail git merge --rerere-autoupdate fifth &&
336 git update-index --refresh
339 test_expect_success 'merge --no-rerere-autoupdate' '
340 headblob=$(git rev-parse version2:file3) &&
341 mergeblob=$(git rev-parse fifth:file3) &&
342 cat >expected <<-EOF &&
343 100644 $headblob 2 file3
344 100644 $mergeblob 3 file3
347 git config rerere.autoupdate true &&
349 git checkout version2 &&
350 test_must_fail git merge --no-rerere-autoupdate fifth &&
351 git ls-files -u >actual &&
352 test_cmp expected actual
355 test_expect_success 'set up an unresolved merge' '
356 headblob=$(git rev-parse version2:file3) &&
357 mergeblob=$(git rev-parse fifth:file3) &&
358 cat >expected.unresolved <<-EOF &&
359 100644 $headblob 2 file3
360 100644 $mergeblob 3 file3
363 test_might_fail git config --unset rerere.autoupdate &&
365 git checkout version2 &&
366 fifth=$(git rev-parse fifth) &&
367 echo "$fifth branch 'fifth' of ." |
368 git fmt-merge-msg >msg &&
369 ancestor=$(git merge-base version2 fifth) &&
370 test_must_fail git merge-recursive "$ancestor" -- HEAD fifth &&
372 git ls-files --stage >failedmerge &&
373 cp file3 file3.conflict &&
375 git ls-files -u >actual &&
376 test_cmp expected.unresolved actual
379 test_expect_success 'explicit rerere' '
380 test_might_fail git config --unset rerere.autoupdate &&
381 git rm -fr --cached . &&
382 git update-index --index-info <failedmerge &&
383 cp file3.conflict file3 &&
384 test_must_fail git update-index --refresh -q &&
387 git ls-files -u >actual &&
388 test_cmp expected.unresolved actual
391 test_expect_success 'explicit rerere with autoupdate' '
392 git config rerere.autoupdate true &&
393 git rm -fr --cached . &&
394 git update-index --index-info <failedmerge &&
395 cp file3.conflict file3 &&
396 test_must_fail git update-index --refresh -q &&
399 git update-index --refresh
402 test_expect_success 'explicit rerere --rerere-autoupdate overrides' '
403 git config rerere.autoupdate false &&
404 git rm -fr --cached . &&
405 git update-index --index-info <failedmerge &&
406 cp file3.conflict file3 &&
408 git ls-files -u >actual1 &&
410 git rm -fr --cached . &&
411 git update-index --index-info <failedmerge &&
412 cp file3.conflict file3 &&
413 git rerere --rerere-autoupdate &&
414 git update-index --refresh &&
416 git rm -fr --cached . &&
417 git update-index --index-info <failedmerge &&
418 cp file3.conflict file3 &&
419 git rerere --rerere-autoupdate --no-rerere-autoupdate &&
420 git ls-files -u >actual2 &&
422 git rm -fr --cached . &&
423 git update-index --index-info <failedmerge &&
424 cp file3.conflict file3 &&
425 git rerere --rerere-autoupdate --no-rerere-autoupdate --rerere-autoupdate &&
426 git update-index --refresh &&
428 test_cmp expected.unresolved actual1 &&
429 test_cmp expected.unresolved actual2
432 test_expect_success 'rerere --no-no-rerere-autoupdate' '
433 git rm -fr --cached . &&
434 git update-index --index-info <failedmerge &&
435 cp file3.conflict file3 &&
436 test_must_fail git rerere --no-no-rerere-autoupdate 2>err &&
437 test_i18ngrep [Uu]sage err &&
438 test_must_fail git update-index --refresh
441 test_expect_success 'rerere -h' '
442 test_must_fail git rerere -h >help &&
443 test_i18ngrep [Uu]sage help
449 cat early && printf "%s\n" "$@" && cat late "$last"
453 find .git/rr-cache/ -type f -name "preimage*" >actual &&
454 test_line_count = "$1" actual &&
455 find .git/rr-cache/ -type f -name "postimage*" >actual &&
456 test_line_count = "$2" actual
459 merge_conflict_resolve () {
461 test_must_fail git merge six.1 &&
462 # Resolution is to replace 7 with 6.1 and 6.2 (i.e. take both)
463 concat_insert short 6.1 6.2 >file1 &&
464 concat_insert long 6.1 6.2 >file2
467 test_expect_success 'multiple identical conflicts' '
468 rm -fr .git/rr-cache &&
469 mkdir .git/rr-cache &&
472 test_seq 1 6 >early &&
474 test_seq 11 15 >short &&
475 test_seq 111 120 >long &&
476 concat_insert short >file1 &&
477 concat_insert long >file2 &&
478 git add file1 file2 &&
479 git commit -m base &&
481 git checkout -b six.1 &&
482 concat_insert short 6.1 >file1 &&
483 concat_insert long 6.1 >file2 &&
484 git add file1 file2 &&
486 git checkout -b six.2 HEAD^ &&
487 concat_insert short 6.2 >file1 &&
488 concat_insert long 6.2 >file2 &&
489 git add file1 file2 &&
492 # At this point, six.1 and six.2
493 # - derive from common ancestor that has two files
494 # 1...6 7 11..15 (file1) and 1...6 7 111..120 (file2)
495 # - six.1 replaces these 7s with 6.1
496 # - six.2 replaces these 7s with 6.2
498 merge_conflict_resolve &&
500 # Check that rerere knows that file1 and file2 have conflicts
502 printf "%s\n" file1 file2 >expect &&
503 git ls-files -u | sed -e "s/^.* //" | sort -u >actual &&
504 test_cmp expect actual &&
506 git rerere status | sort >actual &&
507 test_cmp expect actual &&
509 git rerere remaining >actual &&
510 test_cmp expect actual &&
512 count_pre_post 2 0 &&
514 # Pretend that the conflicts were made quite some time ago
515 test-tool chmtime -172800 $(find .git/rr-cache/ -type f) &&
517 # Unresolved entries have not expired yet
518 git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
519 count_pre_post 2 0 &&
521 # Unresolved entries have expired
522 git -c gc.rerereresolved=5 -c gc.rerereunresolved=1 rerere gc &&
523 count_pre_post 0 0 &&
525 # Recreate the conflicted state
526 merge_conflict_resolve &&
527 count_pre_post 2 0 &&
531 count_pre_post 0 0 &&
533 # Recreate the conflicted state
534 merge_conflict_resolve &&
535 count_pre_post 2 0 &&
537 # We resolved file1 and file2
540 git rerere remaining >actual &&
541 test_cmp expect actual &&
543 # We must have recorded both of them
544 count_pre_post 2 2 &&
546 # Now we should be able to resolve them both
548 test_must_fail git merge six.1 &&
552 git rerere remaining >actual &&
553 test_cmp expect actual &&
555 concat_insert short 6.1 6.2 >file1.expect &&
556 concat_insert long 6.1 6.2 >file2.expect &&
557 test_cmp file1.expect file1 &&
558 test_cmp file2.expect file2 &&
560 # Forget resolution for file2
561 git rerere forget file2 &&
562 echo file2 >expect &&
563 git rerere status >actual &&
564 test_cmp expect actual &&
565 count_pre_post 2 1 &&
567 # file2 already has correct resolution, so record it again
570 # Pretend that the resolutions are old again
571 test-tool chmtime -172800 $(find .git/rr-cache/ -type f) &&
573 # Resolved entries have not expired yet
574 git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
576 count_pre_post 2 2 &&
578 # Resolved entries have expired
579 git -c gc.rerereresolved=1 -c gc.rerereunresolved=5 rerere gc &&