blob: ed9c91e25b584c2241c238f9c6ffad9a3a327d2c [file] [log] [blame]
Johannes Schindelinad8e72c2006-12-21 10:21:28 +01001#!/bin/sh
2#
3# Copyright (c) 2006 Johannes E. Schindelin
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git rerere
Jonathan Niederf7314882010-08-05 06:25:34 -05007
8! [fifth] version1
9 ! [first] first
10 ! [fourth] version1
11 ! [master] initial
12 ! [second] prefer first over second
13 ! [third] version2
14------
15 + [third] version2
16+ [fifth] version1
17 + [fourth] version1
18+ + + [third^] third
19 - [second] prefer first over second
20 + + [first] first
21 + [second^] second
22++++++ [master] initial
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010023'
24
25. ./test-lib.sh
26
Jonathan Niederf7314882010-08-05 06:25:34 -050027test_expect_success 'setup' '
28 cat >a1 <<-\EOF &&
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040029 Some title
30 ==========
Jonathan Niederf7314882010-08-05 06:25:34 -050031 Whether '\''tis nobler in the mind to suffer
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040032 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
Jonathan Niederf7314882010-08-05 06:25:34 -050037 That flesh is heir to, '\''tis a consummation
38 Devoutly to be wish'\''d.
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040039 EOF
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010040
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040041 git add a1 &&
Jonathan Niederf7314882010-08-05 06:25:34 -050042 test_tick &&
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040043 git commit -q -a -m initial &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010044
Jonathan Niederf7314882010-08-05 06:25:34 -050045 cat >>a1 <<-\EOF &&
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040046 Some title
47 ==========
48 To die, to sleep;
Jonathan Niederf7314882010-08-05 06:25:34 -050049 To sleep: perchance to dream: ay, there'\''s the rub;
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040050 For in that sleep of death what dreams may come
51 When we have shuffled off this mortal coil,
Jonathan Niederf7314882010-08-05 06:25:34 -050052 Must give us pause: there'\''s the respect
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040053 That makes calamity of so long life;
54 EOF
Jonathan Niederf7314882010-08-05 06:25:34 -050055
56 git checkout -b first &&
57 test_tick &&
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040058 git commit -q -a -m first &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010059
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040060 git checkout -b second master &&
61 git show first:a1 |
Jonathan Niederf7314882010-08-05 06:25:34 -050062 sed -e "s/To die, t/To die! T/" -e "s/Some title/Some Title/" >a1 &&
63 echo "* END *" >>a1 &&
64 test_tick &&
Brian Gernhardt4a45f7d2010-03-20 04:29:11 -040065 git commit -q -a -m second
Jonathan Niederf7314882010-08-05 06:25:34 -050066'
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010067
Johannes Schindelinb4372ef2007-07-06 13:05:59 +010068test_expect_success 'nothing recorded without rerere' '
Jonathan Niederf7314882010-08-05 06:25:34 -050069 rm -rf .git/rr-cache &&
70 git config rerere.enabled false &&
Stephan Beyerd492b312008-07-12 17:47:52 +020071 test_must_fail git merge first &&
Johannes Schindelinb4372ef2007-07-06 13:05:59 +010072 ! test -d .git/rr-cache
73'
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010074
Jonathan Niederf7314882010-08-05 06:25:34 -050075test_expect_success 'activate rerere, old style (conflicting merge)' '
Johannes Schindelinb4372ef2007-07-06 13:05:59 +010076 git reset --hard &&
77 mkdir .git/rr-cache &&
Jonathan Niederf7314882010-08-05 06:25:34 -050078 test_might_fail git config --unset rerere.enabled &&
79 test_must_fail git merge first &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010080
Jeff King94221d22013-10-28 21:23:03 -040081 sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
Jonathan Niederf7314882010-08-05 06:25:34 -050082 rr=.git/rr-cache/$sha1 &&
83 grep "^=======\$" $rr/preimage &&
84 ! test -f $rr/postimage &&
85 ! test -f $rr/thisimage
86'
Johannes Schindelinad8e72c2006-12-21 10:21:28 +010087
Johannes Schindelinb4372ef2007-07-06 13:05:59 +010088test_expect_success 'rerere.enabled works, too' '
89 rm -rf .git/rr-cache &&
90 git config rerere.enabled true &&
91 git reset --hard &&
Stephan Beyerd492b312008-07-12 17:47:52 +020092 test_must_fail git merge first &&
Jonathan Niederf7314882010-08-05 06:25:34 -050093
Jeff King94221d22013-10-28 21:23:03 -040094 sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
Jonathan Niederf7314882010-08-05 06:25:34 -050095 rr=.git/rr-cache/$sha1 &&
Olivier Marin99d698f2008-07-07 14:42:48 +020096 grep ^=======$ $rr/preimage
Johannes Schindelinb4372ef2007-07-06 13:05:59 +010097'
98
Jonathan Niederf7314882010-08-05 06:25:34 -050099test_expect_success 'set up rr-cache' '
100 rm -rf .git/rr-cache &&
101 git config rerere.enabled true &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100102 git reset --hard &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500103 test_must_fail git merge first &&
Jeff King94221d22013-10-28 21:23:03 -0400104 sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500105 rr=.git/rr-cache/$sha1
106'
Junio C Hamanoeb335962007-04-03 16:28:46 -0700107
Jonathan Niederf7314882010-08-05 06:25:34 -0500108test_expect_success 'rr-cache looks sane' '
109 # no postimage or thisimage yet
110 ! test -f $rr/postimage &&
111 ! test -f $rr/thisimage &&
Junio C Hamanoeb335962007-04-03 16:28:46 -0700112
Jonathan Niederf7314882010-08-05 06:25:34 -0500113 # preimage has right number of lines
Junio C Hamanoeb335962007-04-03 16:28:46 -0700114 cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500115 echo $cnt &&
Junio C Hamanoeb335962007-04-03 16:28:46 -0700116 test $cnt = 13
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100117'
118
Jonathan Niederf7314882010-08-05 06:25:34 -0500119test_expect_success 'rerere diff' '
120 git show first:a1 >a1 &&
121 cat >expect <<-\EOF &&
122 --- a/a1
123 +++ b/a1
124 @@ -1,4 +1,4 @@
125 -Some Title
126 +Some title
127 ==========
128 Whether '\''tis nobler in the mind to suffer
129 The slings and arrows of outrageous fortune,
130 @@ -8,21 +8,11 @@
131 The heart-ache and the thousand natural shocks
132 That flesh is heir to, '\''tis a consummation
133 Devoutly to be wish'\''d.
134 -<<<<<<<
135 -Some Title
136 -==========
137 -To die! To sleep;
138 -=======
139 Some title
140 ==========
141 To die, to sleep;
142 ->>>>>>>
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;
148 -<<<<<<<
149 -=======
150 -* END *
151 ->>>>>>>
152 EOF
153 git rerere diff >out &&
154 test_cmp expect out
155'
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100156
Jonathan Niederf7314882010-08-05 06:25:34 -0500157test_expect_success 'rerere status' '
158 echo a1 >expect &&
159 git rerere status >out &&
160 test_cmp expect out
161'
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100162
Jonathan Niederf7314882010-08-05 06:25:34 -0500163test_expect_success 'first postimage wins' '
164 git show first:a1 | sed "s/To die: t/To die! T/" >expect &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100165
Jonathan Niederf7314882010-08-05 06:25:34 -0500166 git commit -q -a -m "prefer first over second" &&
167 test -f $rr/postimage &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100168
Junio C Hamano8aed4a52010-09-03 09:43:41 -0700169 oldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100170
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100171 git checkout -b third master &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500172 git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100173 git commit -q -a -m third &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500174
Felipe Contreras501a75a2013-10-31 03:25:33 -0600175 test_must_fail git merge first &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500176 # rerere kicked in
177 ! grep "^=======\$" a1 &&
178 test_cmp expect a1
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100179'
180
SZEDER Gábor7d7ff152010-07-13 01:42:04 +0200181test_expect_success 'rerere updates postimage timestamp' '
Junio C Hamano8aed4a52010-09-03 09:43:41 -0700182 newmtimepost=$(test-chmtime -v +0 $rr/postimage | cut -f 1) &&
SZEDER Gábor7d7ff152010-07-13 01:42:04 +0200183 test $oldmtimepost -lt $newmtimepost
184'
185
Jonathan Niederf7314882010-08-05 06:25:34 -0500186test_expect_success 'rerere clear' '
187 rm $rr/postimage &&
Jeff King94221d22013-10-28 21:23:03 -0400188 echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500189 git rerere clear &&
190 ! test -d $rr
191'
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100192
Jonathan Niederf7314882010-08-05 06:25:34 -0500193test_expect_success 'set up for garbage collection tests' '
194 mkdir -p $rr &&
195 echo Hello >$rr/preimage &&
196 echo World >$rr/postimage &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100197
Jonathan Niederf7314882010-08-05 06:25:34 -0500198 sha2=4000000000000000000000000000000000000000 &&
199 rr2=.git/rr-cache/$sha2 &&
200 mkdir $rr2 &&
201 echo Hello >$rr2/preimage &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100202
Jonathan Niederf7314882010-08-05 06:25:34 -0500203 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)) &&
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100207
Junio C Hamano8aed4a52010-09-03 09:43:41 -0700208 test-chmtime =$just_over_60_days_ago $rr/preimage &&
209 test-chmtime =$almost_60_days_ago $rr/postimage &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500210 test-chmtime =$almost_15_days_ago $rr2/preimage
211'
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100212
Junio C Hamano8aed4a52010-09-03 09:43:41 -0700213test_expect_success 'gc preserves young or recently used records' '
Jonathan Niederf7314882010-08-05 06:25:34 -0500214 git rerere gc &&
215 test -f $rr/preimage &&
216 test -f $rr2/preimage
217'
Junio C Hamanofa1b4d22007-02-07 10:42:08 -0800218
Jonathan Niederf7314882010-08-05 06:25:34 -0500219test_expect_success 'old records rest in peace' '
Junio C Hamano8aed4a52010-09-03 09:43:41 -0700220 test-chmtime =$just_over_60_days_ago $rr/postimage &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500221 test-chmtime =$just_over_15_days_ago $rr2/preimage &&
222 git rerere gc &&
223 ! test -f $rr/preimage &&
224 ! test -f $rr2/preimage
225'
Junio C Hamanofa1b4d22007-02-07 10:42:08 -0800226
Jonathan Niederf7314882010-08-05 06:25:34 -0500227test_expect_success 'setup: file2 added differently in two branches' '
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100228 git reset --hard &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500229
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100230 git checkout -b fourth &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500231 echo Hallo >file2 &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100232 git add file2 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500233 test_tick &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100234 git commit -m version1 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500235
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100236 git checkout third &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500237 echo Bello >file2 &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100238 git add file2 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500239 test_tick &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100240 git commit -m version2 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500241
Stephan Beyerd492b312008-07-12 17:47:52 +0200242 test_must_fail git merge fourth &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500243 echo Cello >file2 &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100244 git add file2 &&
245 git commit -m resolution
246'
247
248test_expect_success 'resolution was recorded properly' '
Jonathan Niederf7314882010-08-05 06:25:34 -0500249 echo Cello >expected &&
250
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100251 git reset --hard HEAD~2 &&
252 git checkout -b fifth &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500253
254 echo Hallo >file3 &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100255 git add file3 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500256 test_tick &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100257 git commit -m version1 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500258
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100259 git checkout third &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500260 echo Bello >file3 &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100261 git add file3 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500262 test_tick &&
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100263 git commit -m version2 &&
Junio C Hamano121c8132008-06-22 02:04:31 -0700264 git tag version2 &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500265
Junio C Hamano7f8365f2008-06-22 02:03:26 -0700266 test_must_fail git merge fifth &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500267 test_cmp expected file3 &&
268 test_must_fail git update-index --refresh
Johannes Schindelin52aaf642007-07-09 14:47:24 +0100269'
270
Junio C Hamano121c8132008-06-22 02:04:31 -0700271test_expect_success 'rerere.autoupdate' '
Jonathan Niederf7314882010-08-05 06:25:34 -0500272 git config rerere.autoupdate true &&
Junio C Hamano121c8132008-06-22 02:04:31 -0700273 git reset --hard &&
274 git checkout version2 &&
275 test_must_fail git merge fifth &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500276 git update-index --refresh
Junio C Hamanocb6020b2009-12-04 00:20:48 -0800277'
Junio C Hamano121c8132008-06-22 02:04:31 -0700278
Junio C Hamanocb6020b2009-12-04 00:20:48 -0800279test_expect_success 'merge --rerere-autoupdate' '
Jonathan Niederf7314882010-08-05 06:25:34 -0500280 test_might_fail git config --unset rerere.autoupdate &&
Junio C Hamanocb6020b2009-12-04 00:20:48 -0800281 git reset --hard &&
282 git checkout version2 &&
283 test_must_fail git merge --rerere-autoupdate fifth &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500284 git update-index --refresh
Junio C Hamanocb6020b2009-12-04 00:20:48 -0800285'
286
287test_expect_success 'merge --no-rerere-autoupdate' '
Jonathan Niederf7314882010-08-05 06:25:34 -0500288 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
293 EOF
294
295 git config rerere.autoupdate true &&
Junio C Hamanocb6020b2009-12-04 00:20:48 -0800296 git reset --hard &&
297 git checkout version2 &&
298 test_must_fail git merge --no-rerere-autoupdate fifth &&
Jonathan Niederf7314882010-08-05 06:25:34 -0500299 git ls-files -u >actual &&
300 test_cmp expected actual
Junio C Hamano121c8132008-06-22 02:04:31 -0700301'
302
Jonathan Nieder672d1b72010-08-05 06:28:37 -0500303test_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
309 EOF
310
311 test_might_fail git config --unset rerere.autoupdate &&
312 git reset --hard &&
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 &&
319
320 git ls-files --stage >failedmerge &&
321 cp file3 file3.conflict &&
322
323 git ls-files -u >actual &&
324 test_cmp expected.unresolved actual
325'
326
327test_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 &&
333
334 git rerere &&
335 git ls-files -u >actual &&
336 test_cmp expected.unresolved actual
337'
338
339test_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 &&
345
346 git rerere &&
347 git update-index --refresh
348'
349
350test_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 &&
355 git rerere &&
356 git ls-files -u >actual1 &&
357
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 &&
363
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 &&
369
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 &&
375
376 test_cmp expected.unresolved actual1 &&
377 test_cmp expected.unresolved actual2
378'
379
380test_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 &&
Jiang Xin9a001382012-08-27 13:36:55 +0800385 test_i18ngrep [Uu]sage err &&
Jonathan Nieder672d1b72010-08-05 06:28:37 -0500386 test_must_fail git update-index --refresh
387'
388
389test_expect_success 'rerere -h' '
390 test_must_fail git rerere -h >help &&
Jiang Xin9a001382012-08-27 13:36:55 +0800391 test_i18ngrep [Uu]sage help
Johannes Schindelinad8e72c2006-12-21 10:21:28 +0100392'
393
394test_done