]>
Commit | Line | Data |
---|---|---|
ad8e72cb JS |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2006 Johannes E. Schindelin | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git rerere |
f7314882 JN |
7 | |
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 | |
ad8e72cb JS |
23 | ' |
24 | ||
25 | . ./test-lib.sh | |
26 | ||
f7314882 | 27 | test_expect_success 'setup' ' |
717c939d | 28 | test_oid_init && |
f7314882 | 29 | cat >a1 <<-\EOF && |
4a45f7dd BG |
30 | Some title |
31 | ========== | |
f7314882 | 32 | Whether '\''tis nobler in the mind to suffer |
4a45f7dd BG |
33 | The slings and arrows of outrageous fortune, |
34 | Or to take arms against a sea of troubles, | |
35 | And by opposing end them? To die: to sleep; | |
36 | No more; and by a sleep to say we end | |
37 | The heart-ache and the thousand natural shocks | |
f7314882 JN |
38 | That flesh is heir to, '\''tis a consummation |
39 | Devoutly to be wish'\''d. | |
4a45f7dd | 40 | EOF |
ad8e72cb | 41 | |
4a45f7dd | 42 | git add a1 && |
f7314882 | 43 | test_tick && |
4a45f7dd | 44 | git commit -q -a -m initial && |
ad8e72cb | 45 | |
f7314882 | 46 | cat >>a1 <<-\EOF && |
4a45f7dd BG |
47 | Some title |
48 | ========== | |
49 | To die, to sleep; | |
f7314882 | 50 | To sleep: perchance to dream: ay, there'\''s the rub; |
4a45f7dd BG |
51 | For in that sleep of death what dreams may come |
52 | When we have shuffled off this mortal coil, | |
f7314882 | 53 | Must give us pause: there'\''s the respect |
4a45f7dd BG |
54 | That makes calamity of so long life; |
55 | EOF | |
f7314882 JN |
56 | |
57 | git checkout -b first && | |
58 | test_tick && | |
4a45f7dd | 59 | git commit -q -a -m first && |
ad8e72cb | 60 | |
4a45f7dd BG |
61 | git checkout -b second master && |
62 | git show first:a1 | | |
f7314882 JN |
63 | sed -e "s/To die, t/To die! T/" -e "s/Some title/Some Title/" >a1 && |
64 | echo "* END *" >>a1 && | |
65 | test_tick && | |
4a45f7dd | 66 | git commit -q -a -m second |
f7314882 | 67 | ' |
ad8e72cb | 68 | |
b4372ef1 | 69 | test_expect_success 'nothing recorded without rerere' ' |
f7314882 JN |
70 | rm -rf .git/rr-cache && |
71 | git config rerere.enabled false && | |
d492b31c | 72 | test_must_fail git merge first && |
b4372ef1 JS |
73 | ! test -d .git/rr-cache |
74 | ' | |
ad8e72cb | 75 | |
f7314882 | 76 | test_expect_success 'activate rerere, old style (conflicting merge)' ' |
b4372ef1 JS |
77 | git reset --hard && |
78 | mkdir .git/rr-cache && | |
f7314882 JN |
79 | test_might_fail git config --unset rerere.enabled && |
80 | test_must_fail git merge first && | |
ad8e72cb | 81 | |
94221d22 | 82 | sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) && |
f7314882 JN |
83 | rr=.git/rr-cache/$sha1 && |
84 | grep "^=======\$" $rr/preimage && | |
85 | ! test -f $rr/postimage && | |
86 | ! test -f $rr/thisimage | |
87 | ' | |
ad8e72cb | 88 | |
b4372ef1 JS |
89 | test_expect_success 'rerere.enabled works, too' ' |
90 | rm -rf .git/rr-cache && | |
91 | git config rerere.enabled true && | |
92 | git reset --hard && | |
d492b31c | 93 | test_must_fail git merge first && |
f7314882 | 94 | |
94221d22 | 95 | sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) && |
f7314882 | 96 | rr=.git/rr-cache/$sha1 && |
99d698f1 | 97 | grep ^=======$ $rr/preimage |
b4372ef1 JS |
98 | ' |
99 | ||
f7314882 JN |
100 | test_expect_success 'set up rr-cache' ' |
101 | rm -rf .git/rr-cache && | |
102 | git config rerere.enabled true && | |
103 | git reset --hard && | |
104 | test_must_fail git merge first && | |
94221d22 | 105 | sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) && |
f7314882 JN |
106 | rr=.git/rr-cache/$sha1 |
107 | ' | |
ad8e72cb | 108 | |
f7314882 JN |
109 | test_expect_success 'rr-cache looks sane' ' |
110 | # no postimage or thisimage yet | |
111 | ! test -f $rr/postimage && | |
112 | ! test -f $rr/thisimage && | |
eb335966 | 113 | |
f7314882 | 114 | # preimage has right number of lines |
eb335966 | 115 | cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) && |
f7314882 | 116 | echo $cnt && |
99d698f1 | 117 | test $cnt = 13 |
eb335966 JH |
118 | ' |
119 | ||
f7314882 JN |
120 | test_expect_success 'rerere diff' ' |
121 | git show first:a1 >a1 && | |
122 | cat >expect <<-\EOF && | |
123 | --- a/a1 | |
124 | +++ b/a1 | |
125 | @@ -1,4 +1,4 @@ | |
126 | -Some Title | |
127 | +Some title | |
128 | ========== | |
129 | Whether '\''tis nobler in the mind to suffer | |
130 | The slings and arrows of outrageous fortune, | |
131 | @@ -8,21 +8,11 @@ | |
132 | The heart-ache and the thousand natural shocks | |
133 | That flesh is heir to, '\''tis a consummation | |
134 | Devoutly to be wish'\''d. | |
135 | -<<<<<<< | |
136 | -Some Title | |
137 | -========== | |
138 | -To die! To sleep; | |
139 | -======= | |
140 | Some title | |
141 | ========== | |
142 | To die, to sleep; | |
143 | ->>>>>>> | |
144 | To sleep: perchance to dream: ay, there'\''s the rub; | |
145 | For in that sleep of death what dreams may come | |
146 | When we have shuffled off this mortal coil, | |
147 | Must give us pause: there'\''s the respect | |
148 | That makes calamity of so long life; | |
149 | -<<<<<<< | |
150 | -======= | |
151 | -* END * | |
152 | ->>>>>>> | |
153 | EOF | |
154 | git rerere diff >out && | |
155 | test_cmp expect out | |
52aaf649 | 156 | ' |
ad8e72cb | 157 | |
f7314882 JN |
158 | test_expect_success 'rerere status' ' |
159 | echo a1 >expect && | |
160 | git rerere status >out && | |
161 | test_cmp expect out | |
7d7ff15b SG |
162 | ' |
163 | ||
f7314882 JN |
164 | test_expect_success 'first postimage wins' ' |
165 | git show first:a1 | sed "s/To die: t/To die! T/" >expect && | |
ad8e72cb | 166 | |
f7314882 JN |
167 | git commit -q -a -m "prefer first over second" && |
168 | test -f $rr/postimage && | |
ad8e72cb | 169 | |
deb9845a | 170 | oldmtimepost=$(test-tool chmtime --get -60 $rr/postimage) && |
ad8e72cb | 171 | |
f7314882 JN |
172 | git checkout -b third master && |
173 | git show second^:a1 | sed "s/To die: t/To die! T/" >a1 && | |
174 | git commit -q -a -m third && | |
ad8e72cb | 175 | |
501a75a7 | 176 | test_must_fail git merge first && |
f7314882 JN |
177 | # rerere kicked in |
178 | ! grep "^=======\$" a1 && | |
179 | test_cmp expect a1 | |
180 | ' | |
ad8e72cb | 181 | |
8aed4a5e | 182 | test_expect_success 'rerere updates postimage timestamp' ' |
deb9845a | 183 | newmtimepost=$(test-tool chmtime --get $rr/postimage) && |
8aed4a5e JH |
184 | test $oldmtimepost -lt $newmtimepost |
185 | ' | |
56cf9806 | 186 | |
f7314882 | 187 | test_expect_success 'rerere clear' ' |
05dd9f13 | 188 | mv $rr/postimage .git/post-saved && |
94221d22 | 189 | echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR && |
f7314882 JN |
190 | git rerere clear && |
191 | ! test -d $rr | |
192 | ' | |
56cf9806 | 193 | |
05dd9f13 JH |
194 | test_expect_success 'leftover directory' ' |
195 | git reset --hard && | |
196 | mkdir -p $rr && | |
197 | test_must_fail git merge first && | |
198 | test -f $rr/preimage | |
199 | ' | |
200 | ||
201 | test_expect_success 'missing preimage' ' | |
202 | git reset --hard && | |
203 | mkdir -p $rr && | |
204 | cp .git/post-saved $rr/postimage && | |
205 | test_must_fail git merge first && | |
206 | test -f $rr/preimage | |
207 | ' | |
208 | ||
f7314882 JN |
209 | test_expect_success 'set up for garbage collection tests' ' |
210 | mkdir -p $rr && | |
211 | echo Hello >$rr/preimage && | |
212 | echo World >$rr/postimage && | |
56cf9806 | 213 | |
717c939d | 214 | sha2=$(test_oid deadbeef) && |
f7314882 JN |
215 | rr2=.git/rr-cache/$sha2 && |
216 | mkdir $rr2 && | |
217 | echo Hello >$rr2/preimage && | |
56cf9806 | 218 | |
f7314882 JN |
219 | almost_15_days_ago=$((60-15*86400)) && |
220 | just_over_15_days_ago=$((-1-15*86400)) && | |
221 | almost_60_days_ago=$((60-60*86400)) && | |
222 | just_over_60_days_ago=$((-1-60*86400)) && | |
56cf9806 | 223 | |
0e496492 NTND |
224 | test-tool chmtime =$just_over_60_days_ago $rr/preimage && |
225 | test-tool chmtime =$almost_60_days_ago $rr/postimage && | |
226 | test-tool chmtime =$almost_15_days_ago $rr2/preimage | |
f7314882 | 227 | ' |
56cf9806 | 228 | |
8aed4a5e | 229 | test_expect_success 'gc preserves young or recently used records' ' |
f7314882 JN |
230 | git rerere gc && |
231 | test -f $rr/preimage && | |
232 | test -f $rr2/preimage | |
233 | ' | |
ad8e72cb | 234 | |
f7314882 | 235 | test_expect_success 'old records rest in peace' ' |
0e496492 NTND |
236 | test-tool chmtime =$just_over_60_days_ago $rr/postimage && |
237 | test-tool chmtime =$just_over_15_days_ago $rr2/preimage && | |
f7314882 JN |
238 | git rerere gc && |
239 | ! test -f $rr/preimage && | |
240 | ! test -f $rr2/preimage | |
241 | ' | |
ad8e72cb | 242 | |
e579aaa6 JH |
243 | rerere_gc_custom_expiry_test () { |
244 | five_days="$1" right_now="$2" | |
245 | test_expect_success "rerere gc with custom expiry ($five_days, $right_now)" ' | |
246 | rm -fr .git/rr-cache && | |
8125a58b | 247 | rr=.git/rr-cache/$ZERO_OID && |
e579aaa6 JH |
248 | mkdir -p "$rr" && |
249 | >"$rr/preimage" && | |
250 | >"$rr/postimage" && | |
251 | ||
252 | two_days_ago=$((-2*86400)) && | |
0e496492 NTND |
253 | test-tool chmtime =$two_days_ago "$rr/preimage" && |
254 | test-tool chmtime =$two_days_ago "$rr/postimage" && | |
e579aaa6 JH |
255 | |
256 | find .git/rr-cache -type f | sort >original && | |
257 | ||
258 | git -c "gc.rerereresolved=$five_days" \ | |
259 | -c "gc.rerereunresolved=$five_days" rerere gc && | |
260 | find .git/rr-cache -type f | sort >actual && | |
261 | test_cmp original actual && | |
262 | ||
263 | git -c "gc.rerereresolved=$five_days" \ | |
264 | -c "gc.rerereunresolved=$right_now" rerere gc && | |
265 | find .git/rr-cache -type f | sort >actual && | |
266 | test_cmp original actual && | |
267 | ||
268 | git -c "gc.rerereresolved=$right_now" \ | |
269 | -c "gc.rerereunresolved=$right_now" rerere gc && | |
270 | find .git/rr-cache -type f | sort >actual && | |
d3c6751b | 271 | test_must_be_empty actual |
e579aaa6 JH |
272 | ' |
273 | } | |
274 | ||
275 | rerere_gc_custom_expiry_test 5 0 | |
1ad8b473 | 276 | |
6e96cb52 JH |
277 | rerere_gc_custom_expiry_test 5.days.ago now |
278 | ||
f7314882 | 279 | test_expect_success 'setup: file2 added differently in two branches' ' |
52aaf649 | 280 | git reset --hard && |
f7314882 | 281 | |
52aaf649 | 282 | git checkout -b fourth && |
f7314882 | 283 | echo Hallo >file2 && |
52aaf649 | 284 | git add file2 && |
f7314882 | 285 | test_tick && |
52aaf649 | 286 | git commit -m version1 && |
f7314882 | 287 | |
52aaf649 | 288 | git checkout third && |
f7314882 | 289 | echo Bello >file2 && |
52aaf649 | 290 | git add file2 && |
f7314882 | 291 | test_tick && |
52aaf649 | 292 | git commit -m version2 && |
f7314882 | 293 | |
d492b31c | 294 | test_must_fail git merge fourth && |
f7314882 | 295 | echo Cello >file2 && |
52aaf649 JS |
296 | git add file2 && |
297 | git commit -m resolution | |
298 | ' | |
299 | ||
300 | test_expect_success 'resolution was recorded properly' ' | |
f7314882 JN |
301 | echo Cello >expected && |
302 | ||
52aaf649 JS |
303 | git reset --hard HEAD~2 && |
304 | git checkout -b fifth && | |
f7314882 JN |
305 | |
306 | echo Hallo >file3 && | |
52aaf649 | 307 | git add file3 && |
f7314882 | 308 | test_tick && |
52aaf649 | 309 | git commit -m version1 && |
f7314882 | 310 | |
52aaf649 | 311 | git checkout third && |
f7314882 | 312 | echo Bello >file3 && |
52aaf649 | 313 | git add file3 && |
f7314882 | 314 | test_tick && |
52aaf649 | 315 | git commit -m version2 && |
121c813f | 316 | git tag version2 && |
f7314882 | 317 | |
7f8365f8 | 318 | test_must_fail git merge fifth && |
f7314882 JN |
319 | test_cmp expected file3 && |
320 | test_must_fail git update-index --refresh | |
52aaf649 JS |
321 | ' |
322 | ||
121c813f | 323 | test_expect_success 'rerere.autoupdate' ' |
f7314882 | 324 | git config rerere.autoupdate true && |
121c813f JH |
325 | git reset --hard && |
326 | git checkout version2 && | |
327 | test_must_fail git merge fifth && | |
f7314882 | 328 | git update-index --refresh |
cb6020bb | 329 | ' |
121c813f | 330 | |
cb6020bb | 331 | test_expect_success 'merge --rerere-autoupdate' ' |
f7314882 | 332 | test_might_fail git config --unset rerere.autoupdate && |
cb6020bb JH |
333 | git reset --hard && |
334 | git checkout version2 && | |
335 | test_must_fail git merge --rerere-autoupdate fifth && | |
f7314882 | 336 | git update-index --refresh |
cb6020bb JH |
337 | ' |
338 | ||
339 | test_expect_success 'merge --no-rerere-autoupdate' ' | |
f7314882 JN |
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 | |
345 | EOF | |
346 | ||
347 | git config rerere.autoupdate true && | |
cb6020bb JH |
348 | git reset --hard && |
349 | git checkout version2 && | |
350 | test_must_fail git merge --no-rerere-autoupdate fifth && | |
f7314882 JN |
351 | git ls-files -u >actual && |
352 | test_cmp expected actual | |
121c813f JH |
353 | ' |
354 | ||
672d1b78 JN |
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 | |
361 | EOF | |
362 | ||
363 | test_might_fail git config --unset rerere.autoupdate && | |
364 | git reset --hard && | |
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 && | |
371 | ||
372 | git ls-files --stage >failedmerge && | |
373 | cp file3 file3.conflict && | |
374 | ||
375 | git ls-files -u >actual && | |
376 | test_cmp expected.unresolved actual | |
377 | ' | |
378 | ||
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 && | |
385 | ||
386 | git rerere && | |
387 | git ls-files -u >actual && | |
388 | test_cmp expected.unresolved actual | |
389 | ' | |
390 | ||
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 && | |
397 | ||
398 | git rerere && | |
399 | git update-index --refresh | |
400 | ' | |
401 | ||
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 && | |
407 | git rerere && | |
408 | git ls-files -u >actual1 && | |
409 | ||
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 && | |
415 | ||
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 && | |
421 | ||
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 && | |
427 | ||
428 | test_cmp expected.unresolved actual1 && | |
429 | test_cmp expected.unresolved actual2 | |
430 | ' | |
431 | ||
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 && | |
9a001381 | 437 | test_i18ngrep [Uu]sage err && |
672d1b78 JN |
438 | test_must_fail git update-index --refresh |
439 | ' | |
440 | ||
441 | test_expect_success 'rerere -h' ' | |
442 | test_must_fail git rerere -h >help && | |
9a001381 | 443 | test_i18ngrep [Uu]sage help |
121c813f JH |
444 | ' |
445 | ||
82efa6e2 JH |
446 | concat_insert () { |
447 | last=$1 | |
448 | shift | |
449 | cat early && printf "%s\n" "$@" && cat late "$last" | |
450 | } | |
451 | ||
1be1e851 JH |
452 | count_pre_post () { |
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 | |
457 | } | |
458 | ||
1be1e851 JH |
459 | merge_conflict_resolve () { |
460 | git reset --hard && | |
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 | |
465 | } | |
466 | ||
629716d2 | 467 | test_expect_success 'multiple identical conflicts' ' |
780fbeba JH |
468 | rm -fr .git/rr-cache && |
469 | mkdir .git/rr-cache && | |
82efa6e2 JH |
470 | git reset --hard && |
471 | ||
472 | test_seq 1 6 >early && | |
473 | >late && | |
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 && | |
480 | git tag 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 && | |
485 | git commit -m 6.1 && | |
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 && | |
490 | git commit -m 6.2 && | |
491 | ||
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 | |
497 | ||
1be1e851 | 498 | merge_conflict_resolve && |
82efa6e2 JH |
499 | |
500 | # Check that rerere knows that file1 and file2 have conflicts | |
501 | ||
502 | printf "%s\n" file1 file2 >expect && | |
503 | git ls-files -u | sed -e "s/^.* //" | sort -u >actual && | |
504 | test_cmp expect actual && | |
505 | ||
506 | git rerere status | sort >actual && | |
507 | test_cmp expect actual && | |
508 | ||
82efa6e2 JH |
509 | git rerere remaining >actual && |
510 | test_cmp expect actual && | |
511 | ||
1be1e851 JH |
512 | count_pre_post 2 0 && |
513 | ||
514 | # Pretend that the conflicts were made quite some time ago | |
deb9845a | 515 | test-tool chmtime -172800 $(find .git/rr-cache/ -type f) && |
1be1e851 JH |
516 | |
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 && | |
520 | ||
521 | # Unresolved entries have expired | |
522 | git -c gc.rerereresolved=5 -c gc.rerereunresolved=1 rerere gc && | |
523 | count_pre_post 0 0 && | |
524 | ||
525 | # Recreate the conflicted state | |
526 | merge_conflict_resolve && | |
527 | count_pre_post 2 0 && | |
528 | ||
529 | # Clear it | |
530 | git rerere clear && | |
531 | count_pre_post 0 0 && | |
532 | ||
533 | # Recreate the conflicted state | |
534 | merge_conflict_resolve && | |
535 | count_pre_post 2 0 && | |
536 | ||
82efa6e2 JH |
537 | # We resolved file1 and file2 |
538 | git rerere && | |
82efa6e2 | 539 | git rerere remaining >actual && |
d3c6751b | 540 | test_must_be_empty actual && |
82efa6e2 | 541 | |
1be1e851 JH |
542 | # We must have recorded both of them |
543 | count_pre_post 2 2 && | |
544 | ||
82efa6e2 JH |
545 | # Now we should be able to resolve them both |
546 | git reset --hard && | |
547 | test_must_fail git merge six.1 && | |
548 | git rerere && | |
549 | ||
82efa6e2 | 550 | git rerere remaining >actual && |
d3c6751b | 551 | test_must_be_empty actual && |
82efa6e2 JH |
552 | |
553 | concat_insert short 6.1 6.2 >file1.expect && | |
554 | concat_insert long 6.1 6.2 >file2.expect && | |
555 | test_cmp file1.expect file1 && | |
1be1e851 JH |
556 | test_cmp file2.expect file2 && |
557 | ||
890fca84 JH |
558 | # Forget resolution for file2 |
559 | git rerere forget file2 && | |
560 | echo file2 >expect && | |
561 | git rerere status >actual && | |
562 | test_cmp expect actual && | |
563 | count_pre_post 2 1 && | |
564 | ||
565 | # file2 already has correct resolution, so record it again | |
566 | git rerere && | |
567 | ||
1be1e851 | 568 | # Pretend that the resolutions are old again |
deb9845a | 569 | test-tool chmtime -172800 $(find .git/rr-cache/ -type f) && |
1be1e851 JH |
570 | |
571 | # Resolved entries have not expired yet | |
572 | git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc && | |
573 | ||
574 | count_pre_post 2 2 && | |
575 | ||
576 | # Resolved entries have expired | |
577 | git -c gc.rerereresolved=1 -c gc.rerereunresolved=5 rerere gc && | |
578 | count_pre_post 0 0 | |
82efa6e2 JH |
579 | ' |
580 | ||
93406a28 TG |
581 | test_expect_success 'rerere with unexpected conflict markers does not crash' ' |
582 | git reset --hard && | |
583 | ||
584 | git checkout -b branch-1 master && | |
585 | echo "bar" >test && | |
586 | git add test && | |
587 | git commit -q -m two && | |
588 | ||
589 | git reset --hard && | |
590 | git checkout -b branch-2 master && | |
591 | echo "foo" >test && | |
592 | git add test && | |
593 | git commit -q -a -m one && | |
594 | ||
595 | test_must_fail git merge branch-1 && | |
596 | echo "<<<<<<< a" >test && | |
597 | git rerere && | |
598 | ||
599 | git rerere clear | |
600 | ' | |
601 | ||
4af32207 TG |
602 | test_expect_success 'rerere with inner conflict markers' ' |
603 | git reset --hard && | |
604 | ||
605 | git checkout -b A master && | |
606 | echo "bar" >test && | |
607 | git add test && | |
608 | git commit -q -m two && | |
609 | echo "baz" >test && | |
610 | git add test && | |
611 | git commit -q -m three && | |
612 | ||
613 | git reset --hard && | |
614 | git checkout -b B master && | |
615 | echo "foo" >test && | |
616 | git add test && | |
617 | git commit -q -a -m one && | |
618 | ||
619 | test_must_fail git merge A~ && | |
620 | git add test && | |
621 | git commit -q -m "will solve conflicts later" && | |
622 | test_must_fail git merge A && | |
623 | ||
624 | echo "resolved" >test && | |
625 | git add test && | |
626 | git commit -q -m "solved conflict" && | |
627 | ||
628 | echo "resolved" >expect && | |
629 | ||
630 | git reset --hard HEAD~~ && | |
631 | test_must_fail git merge A~ && | |
632 | git add test && | |
633 | git commit -q -m "will solve conflicts later" && | |
634 | test_must_fail git merge A && | |
635 | cat test >actual && | |
bd7dfa54 TG |
636 | test_cmp expect actual && |
637 | ||
638 | git add test && | |
639 | git commit -m "rerere solved conflict" && | |
640 | git reset --hard HEAD~ && | |
641 | test_must_fail git merge A && | |
642 | cat test >actual && | |
4af32207 TG |
643 | test_cmp expect actual |
644 | ' | |
645 | ||
38c93c4d EN |
646 | test_expect_success 'setup simple stage 1 handling' ' |
647 | test_create_repo stage_1_handling && | |
648 | ( | |
649 | cd stage_1_handling && | |
650 | ||
651 | test_seq 1 10 >original && | |
652 | git add original && | |
653 | git commit -m original && | |
654 | ||
655 | git checkout -b A master && | |
656 | git mv original A && | |
657 | git commit -m "rename to A" && | |
658 | ||
659 | git checkout -b B master && | |
660 | git mv original B && | |
661 | git commit -m "rename to B" | |
662 | ) | |
663 | ' | |
664 | ||
ad2bf0d9 | 665 | test_expect_success 'test simple stage 1 handling' ' |
38c93c4d EN |
666 | ( |
667 | cd stage_1_handling && | |
668 | ||
669 | git config rerere.enabled true && | |
670 | git checkout A^0 && | |
671 | test_must_fail git merge B^0 | |
672 | ) | |
673 | ' | |
674 | ||
ad8e72cb | 675 | test_done |