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-chmtime -v -60 $rr/postimage | cut -f 1) &&
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-chmtime -v +0 $rr/postimage | cut -f 1) &&
183 test $oldmtimepost -lt $newmtimepost
186 test_expect_success 'rerere clear' '
188 echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
193 test_expect_success 'set up for garbage collection tests' '
195 echo Hello >$rr/preimage &&
196 echo World >$rr/postimage &&
198 sha2=4000000000000000000000000000000000000000 &&
199 rr2=.git/rr-cache/$sha2 &&
201 echo Hello >$rr2/preimage &&
203 almost_15_days_ago=$((60-15*86400)) &&
204 just_over_15_days_ago=$((-1-15*86400)) &&
205 almost_60_days_ago=$((60-60*86400)) &&
206 just_over_60_days_ago=$((-1-60*86400)) &&
208 test-chmtime =$just_over_60_days_ago $rr/preimage &&
209 test-chmtime =$almost_60_days_ago $rr/postimage &&
210 test-chmtime =$almost_15_days_ago $rr2/preimage
213 test_expect_success 'gc preserves young or recently used records' '
215 test -f $rr/preimage &&
216 test -f $rr2/preimage
219 test_expect_success 'old records rest in peace' '
220 test-chmtime =$just_over_60_days_ago $rr/postimage &&
221 test-chmtime =$just_over_15_days_ago $rr2/preimage &&
223 ! test -f $rr/preimage &&
224 ! test -f $rr2/preimage
227 test_expect_success 'setup: file2 added differently in two branches' '
230 git checkout -b fourth &&
234 git commit -m version1 &&
236 git checkout third &&
240 git commit -m version2 &&
242 test_must_fail git merge fourth &&
245 git commit -m resolution
248 test_expect_success 'resolution was recorded properly' '
249 echo Cello >expected &&
251 git reset --hard HEAD~2 &&
252 git checkout -b fifth &&
257 git commit -m version1 &&
259 git checkout third &&
263 git commit -m version2 &&
266 test_must_fail git merge fifth &&
267 test_cmp expected file3 &&
268 test_must_fail git update-index --refresh
271 test_expect_success 'rerere.autoupdate' '
272 git config rerere.autoupdate true &&
274 git checkout version2 &&
275 test_must_fail git merge fifth &&
276 git update-index --refresh
279 test_expect_success 'merge --rerere-autoupdate' '
280 test_might_fail git config --unset rerere.autoupdate &&
282 git checkout version2 &&
283 test_must_fail git merge --rerere-autoupdate fifth &&
284 git update-index --refresh
287 test_expect_success 'merge --no-rerere-autoupdate' '
288 headblob=$(git rev-parse version2:file3) &&
289 mergeblob=$(git rev-parse fifth:file3) &&
290 cat >expected <<-EOF &&
291 100644 $headblob 2 file3
292 100644 $mergeblob 3 file3
295 git config rerere.autoupdate true &&
297 git checkout version2 &&
298 test_must_fail git merge --no-rerere-autoupdate fifth &&
299 git ls-files -u >actual &&
300 test_cmp expected actual
303 test_expect_success 'set up an unresolved merge' '
304 headblob=$(git rev-parse version2:file3) &&
305 mergeblob=$(git rev-parse fifth:file3) &&
306 cat >expected.unresolved <<-EOF &&
307 100644 $headblob 2 file3
308 100644 $mergeblob 3 file3
311 test_might_fail git config --unset rerere.autoupdate &&
313 git checkout version2 &&
314 fifth=$(git rev-parse fifth) &&
315 echo "$fifth branch 'fifth' of ." |
316 git fmt-merge-msg >msg &&
317 ancestor=$(git merge-base version2 fifth) &&
318 test_must_fail git merge-recursive "$ancestor" -- HEAD fifth &&
320 git ls-files --stage >failedmerge &&
321 cp file3 file3.conflict &&
323 git ls-files -u >actual &&
324 test_cmp expected.unresolved actual
327 test_expect_success 'explicit rerere' '
328 test_might_fail git config --unset rerere.autoupdate &&
329 git rm -fr --cached . &&
330 git update-index --index-info <failedmerge &&
331 cp file3.conflict file3 &&
332 test_must_fail git update-index --refresh -q &&
335 git ls-files -u >actual &&
336 test_cmp expected.unresolved actual
339 test_expect_success 'explicit rerere with autoupdate' '
340 git config rerere.autoupdate true &&
341 git rm -fr --cached . &&
342 git update-index --index-info <failedmerge &&
343 cp file3.conflict file3 &&
344 test_must_fail git update-index --refresh -q &&
347 git update-index --refresh
350 test_expect_success 'explicit rerere --rerere-autoupdate overrides' '
351 git config rerere.autoupdate false &&
352 git rm -fr --cached . &&
353 git update-index --index-info <failedmerge &&
354 cp file3.conflict file3 &&
356 git ls-files -u >actual1 &&
358 git rm -fr --cached . &&
359 git update-index --index-info <failedmerge &&
360 cp file3.conflict file3 &&
361 git rerere --rerere-autoupdate &&
362 git update-index --refresh &&
364 git rm -fr --cached . &&
365 git update-index --index-info <failedmerge &&
366 cp file3.conflict file3 &&
367 git rerere --rerere-autoupdate --no-rerere-autoupdate &&
368 git ls-files -u >actual2 &&
370 git rm -fr --cached . &&
371 git update-index --index-info <failedmerge &&
372 cp file3.conflict file3 &&
373 git rerere --rerere-autoupdate --no-rerere-autoupdate --rerere-autoupdate &&
374 git update-index --refresh &&
376 test_cmp expected.unresolved actual1 &&
377 test_cmp expected.unresolved actual2
380 test_expect_success 'rerere --no-no-rerere-autoupdate' '
381 git rm -fr --cached . &&
382 git update-index --index-info <failedmerge &&
383 cp file3.conflict file3 &&
384 test_must_fail git rerere --no-no-rerere-autoupdate 2>err &&
385 test_i18ngrep [Uu]sage err &&
386 test_must_fail git update-index --refresh
389 test_expect_success 'rerere -h' '
390 test_must_fail git rerere -h >help &&
391 test_i18ngrep [Uu]sage help