git
[Ported from github.com/git/git] Sync with Git 2.56.1
Brought by drakestapleton
| 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Johannes E. Schindelin |
| 4 | # |
| 5 | |
| 6 | test_description='git rerere |
| 7 | |
| 8 | ! [fifth] version1 |
| 9 | ! [first] first |
| 10 | ! [fourth] version1 |
| 11 | ! [main] 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 | ++++++ [main] initial |
| 23 | ' |
| 24 | |
| 25 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 26 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 27 | |
| 28 | . ./test-lib.sh |
| 29 | |
| 30 | test_expect_success 'setup' ' |
| 31 | cat >a1 <<-\EOF && |
| 32 | Some title |
| 33 | ========== |
| 34 | Whether '\''tis nobler in the mind to suffer |
| 35 | The slings and arrows of outrageous fortune, |
| 36 | Or to take arms against a sea of troubles, |
| 37 | And by opposing end them? To die: to sleep; |
| 38 | No more; and by a sleep to say we end |
| 39 | The heart-ache and the thousand natural shocks |
| 40 | That flesh is heir to, '\''tis a consummation |
| 41 | Devoutly to be wish'\''d. |
| 42 | EOF |
| 43 | |
| 44 | git add a1 && |
| 45 | test_tick && |
| 46 | git commit -q -a -m initial && |
| 47 | |
| 48 | cat >>a1 <<-\EOF && |
| 49 | Some title |
| 50 | ========== |
| 51 | To die, to sleep; |
| 52 | To sleep: perchance to dream: ay, there'\''s the rub; |
| 53 | For in that sleep of death what dreams may come |
| 54 | When we have shuffled off this mortal coil, |
| 55 | Must give us pause: there'\''s the respect |
| 56 | That makes calamity of so long life; |
| 57 | EOF |
| 58 | |
| 59 | git checkout -b first && |
| 60 | test_tick && |
| 61 | git commit -q -a -m first && |
| 62 | |
| 63 | git checkout -b second main && |
| 64 | git show first:a1 | |
| 65 | sed -e "s/To die, t/To die! T/" -e "s/Some title/Some Title/" >a1 && |
| 66 | echo "* END *" >>a1 && |
| 67 | test_tick && |
| 68 | git commit -q -a -m second |
| 69 | ' |
| 70 | |
| 71 | test_expect_success 'nothing recorded without rerere' ' |
| 72 | rm -rf .git/rr-cache && |
| 73 | git config rerere.enabled false && |
| 74 | test_must_fail git merge first && |
| 75 | test_path_is_missing .git/rr-cache |
| 76 | ' |
| 77 | |
| 78 | test_expect_success 'activate rerere, old style (conflicting merge)' ' |
| 79 | git reset --hard && |
| 80 | mkdir .git/rr-cache && |
| 81 | test_might_fail git config --unset rerere.enabled && |
| 82 | test_must_fail git merge first && |
| 83 | |
| 84 | sha1=$(sed "s/ .*//" .git/MERGE_RR) && |
| 85 | rr=.git/rr-cache/$sha1 && |
| 86 | test_grep "^=======\$" $rr/preimage && |
| 87 | test_path_is_missing $rr/postimage && |
| 88 | test_path_is_missing $rr/thisimage |
| 89 | ' |
| 90 | |
| 91 | test_expect_success 'rerere.enabled works, too' ' |
| 92 | rm -rf .git/rr-cache && |
| 93 | git config rerere.enabled true && |
| 94 | git reset --hard && |
| 95 | test_must_fail git merge first && |
| 96 | |
| 97 | sha1=$(sed "s/ .*//" .git/MERGE_RR) && |
| 98 | rr=.git/rr-cache/$sha1 && |
| 99 | test_grep ^=======$ $rr/preimage |
| 100 | ' |
| 101 | |
| 102 | test_expect_success 'set up rr-cache' ' |
| 103 | rm -rf .git/rr-cache && |
| 104 | git config rerere.enabled true && |
| 105 | git reset --hard && |
| 106 | test_must_fail git merge first && |
| 107 | sha1=$(sed "s/ .*//" .git/MERGE_RR) && |
| 108 | rr=.git/rr-cache/$sha1 |
| 109 | ' |
| 110 | |
| 111 | test_expect_success 'rr-cache looks sane' ' |
| 112 | # no postimage or thisimage yet |
| 113 | test_path_is_missing $rr/postimage && |
| 114 | test_path_is_missing $rr/thisimage && |
| 115 | |
| 116 | # preimage has right number of lines |
| 117 | cnt=$(sed -ne "/^<<<<<<</,/^>>>>>>>/p" $rr/preimage | wc -l) && |
| 118 | echo $cnt && |
| 119 | test $cnt = 13 |
| 120 | ' |
| 121 | |
| 122 | test_expect_success 'rerere diff' ' |
| 123 | git show first:a1 >a1 && |
| 124 | cat >expect <<-\EOF && |
| 125 | --- a/a1 |
| 126 | +++ b/a1 |
| 127 | @@ -1,4 +1,4 @@ |
| 128 | -Some Title |
| 129 | +Some title |
| 130 | ========== |
| 131 | Whether '\''tis nobler in the mind to suffer |
| 132 | The slings and arrows of outrageous fortune, |
| 133 | @@ -8,21 +8,11 @@ |
| 134 | The heart-ache and the thousand natural shocks |
| 135 | That flesh is heir to, '\''tis a consummation |
| 136 | Devoutly to be wish'\''d. |
| 137 | -<<<<<<< |
| 138 | -Some Title |
| 139 | -========== |
| 140 | -To die! To sleep; |
| 141 | -======= |
| 142 | Some title |
| 143 | ========== |
| 144 | To die, to sleep; |
| 145 | ->>>>>>> |
| 146 | To sleep: perchance to dream: ay, there'\''s the rub; |
| 147 | For in that sleep of death what dreams may come |
| 148 | When we have shuffled off this mortal coil, |
| 149 | Must give us pause: there'\''s the respect |
| 150 | That makes calamity of so long life; |
| 151 | -<<<<<<< |
| 152 | -======= |
| 153 | -* END * |
| 154 | ->>>>>>> |
| 155 | EOF |
| 156 | git rerere diff >out && |
| 157 | test_cmp expect out |
| 158 | ' |
| 159 | |
| 160 | test_expect_success 'rerere status' ' |
| 161 | echo a1 >expect && |
| 162 | git rerere status >out && |
| 163 | test_cmp expect out |
| 164 | ' |
| 165 | |
| 166 | test_expect_success 'first postimage wins' ' |
| 167 | git show first:a1 | sed "s/To die: t/To die! T/" >expect && |
| 168 | |
| 169 | git commit -q -a -m "prefer first over second" && |
| 170 | test_path_is_file $rr/postimage && |
| 171 | |
| 172 | oldmtimepost=$(test-tool chmtime --get -60 $rr/postimage) && |
| 173 | |
| 174 | git checkout -b third main && |
| 175 | git show second^:a1 | sed "s/To die: t/To die! T/" >a1 && |
| 176 | git commit -q -a -m third && |
| 177 | |
| 178 | test_must_fail git merge first && |
| 179 | # rerere kicked in |
| 180 | test_grep ! "^=======\$" a1 && |
| 181 | test_cmp expect a1 |
| 182 | ' |
| 183 | |
| 184 | test_expect_success 'rerere updates postimage timestamp' ' |
| 185 | newmtimepost=$(test-tool chmtime --get $rr/postimage) && |
| 186 | test $oldmtimepost -lt $newmtimepost |
| 187 | ' |
| 188 | |
| 189 | test_expect_success 'rerere clear' ' |
| 190 | mv $rr/postimage .git/post-saved && |
| 191 | echo "$sha1 a1" | tr "\012" "\000" >.git/MERGE_RR && |
| 192 | git rerere clear && |
| 193 | test_path_is_missing $rr |
| 194 | ' |
| 195 | |
| 196 | test_expect_success 'leftover directory' ' |
| 197 | git reset --hard && |
| 198 | mkdir -p $rr && |
| 199 | test_must_fail git merge first && |
| 200 | test_path_is_file $rr/preimage |
| 201 | ' |
| 202 | |
| 203 | test_expect_success 'missing preimage' ' |
| 204 | git reset --hard && |
| 205 | mkdir -p $rr && |
| 206 | cp .git/post-saved $rr/postimage && |
| 207 | test_must_fail git merge first && |
| 208 | test_path_is_file $rr/preimage |
| 209 | ' |
| 210 | |
| 211 | test_expect_success 'set up for garbage collection tests' ' |
| 212 | mkdir -p $rr && |
| 213 | echo Hello >$rr/preimage && |
| 214 | echo World >$rr/postimage && |
| 215 | |
| 216 | sha2=$(test_oid deadbeef) && |
| 217 | rr2=.git/rr-cache/$sha2 && |
| 218 | mkdir $rr2 && |
| 219 | echo Hello >$rr2/preimage && |
| 220 | |
| 221 | almost_15_days_ago=$((60-15*86400)) && |
| 222 | just_over_15_days_ago=$((-1-15*86400)) && |
| 223 | almost_60_days_ago=$((60-60*86400)) && |
| 224 | just_over_60_days_ago=$((-1-60*86400)) && |
| 225 | |
| 226 | test-tool chmtime =$just_over_60_days_ago $rr/preimage && |
| 227 | test-tool chmtime =$almost_60_days_ago $rr/postimage && |
| 228 | test-tool chmtime =$almost_15_days_ago $rr2/preimage |
| 229 | ' |
| 230 | |
| 231 | test_expect_success 'gc preserves young or recently used records' ' |
| 232 | git rerere gc && |
| 233 | test_path_is_file $rr/preimage && |
| 234 | test_path_is_file $rr2/preimage |
| 235 | ' |
| 236 | |
| 237 | test_expect_success 'old records rest in peace' ' |
| 238 | test-tool chmtime =$just_over_60_days_ago $rr/postimage && |
| 239 | test-tool chmtime =$just_over_15_days_ago $rr2/preimage && |
| 240 | git rerere gc && |
| 241 | test_path_is_missing $rr/preimage && |
| 242 | test_path_is_missing $rr2/preimage |
| 243 | ' |
| 244 | |
| 245 | test_expect_success 'gc --skip-locked does nothing while MERGE_RR is locked' ' |
| 246 | mkdir -p $rr2 && |
| 247 | echo Hello >$rr2/preimage && |
| 248 | test-tool chmtime =$just_over_15_days_ago $rr2/preimage && |
| 249 | |
| 250 | test_when_finished "rm -f .git/MERGE_RR.lock" && |
| 251 | >.git/MERGE_RR.lock && |
| 252 | git rerere gc --skip-locked 2>err && |
| 253 | test_must_be_empty err && |
| 254 | test_path_is_file $rr2/preimage |
| 255 | ' |
| 256 | |
| 257 | test_expect_success 'gc --skip-locked prunes while MERGE_RR is not locked' ' |
| 258 | mkdir -p $rr2 && |
| 259 | echo Hello >$rr2/preimage && |
| 260 | test-tool chmtime =$just_over_15_days_ago $rr2/preimage && |
| 261 | |
| 262 | git rerere gc --skip-locked && |
| 263 | test_path_is_missing $rr2/preimage |
| 264 | ' |
| 265 | |
| 266 | test_expect_success '--skip-locked is only accepted by gc' ' |
| 267 | test_must_fail git rerere --skip-locked clear 2>err && |
| 268 | test_grep "option .--skip-locked. requires .gc." err |
| 269 | ' |
| 270 | |
| 271 | test_expect_success 'a held lock is waited out within rerere.lockTimeout' ' |
| 272 | git reset --hard && |
| 273 | rm -rf $rr && |
| 274 | test_when_finished "wait && rm -f .git/MERGE_RR.lock" && |
| 275 | >.git/MERGE_RR.lock && |
| 276 | { |
| 277 | ( sleep 1 && rm -f .git/MERGE_RR.lock ) & |
| 278 | } && |
| 279 | test_must_fail git -c rerere.lockTimeout=5000 merge first 2>err && |
| 280 | test_grep ! "Unable to create.*MERGE_RR\.lock" err && |
| 281 | test_grep "^=======\$" $rr/preimage |
| 282 | ' |
| 283 | |
| 284 | test_expect_success 'merge fails on a lock it cannot take' ' |
| 285 | git reset --hard && |
| 286 | rm -rf $rr && |
| 287 | test_when_finished "rm -f .git/MERGE_RR.lock" && |
| 288 | >.git/MERGE_RR.lock && |
| 289 | test_must_fail git -c rerere.lockTimeout=0 merge first 2>err && |
| 290 | test_grep "Unable to create.*MERGE_RR\.lock" err && |
| 291 | test_grep "^=======\$" a1 && |
| 292 | test_path_is_missing $rr/preimage |
| 293 | ' |
| 294 | |
| 295 | test_expect_success 'rerere, forget, clear and gc fail on a lock they cannot take' ' |
| 296 | test_when_finished "rm -f .git/MERGE_RR.lock" && |
| 297 | >.git/MERGE_RR.lock && |
| 298 | test_must_fail git -c rerere.lockTimeout=0 rerere 2>err && |
| 299 | test_grep "Unable to create.*MERGE_RR\.lock" err && |
| 300 | test_must_fail git -c rerere.lockTimeout=0 rerere forget a1 2>err && |
| 301 | test_grep "Unable to create.*MERGE_RR\.lock" err && |
| 302 | test_must_fail git -c rerere.lockTimeout=0 rerere clear 2>err && |
| 303 | test_grep "Unable to create.*MERGE_RR\.lock" err && |
| 304 | test_must_fail git -c rerere.lockTimeout=0 rerere gc 2>err && |
| 305 | test_grep "Unable to create.*MERGE_RR\.lock" err |
| 306 | ' |
| 307 | |
| 308 | test_expect_success 'rebase --abort fails on a lock it cannot take' ' |
| 309 | git reset --hard && |
| 310 | git checkout -b lock-held-abort third && |
| 311 | test_when_finished "git checkout third && git branch -D lock-held-abort" && |
| 312 | test_must_fail git rebase first && |
| 313 | test_when_finished "test_might_fail git rebase --abort" && |
| 314 | test_when_finished "rm -f .git/MERGE_RR.lock" && |
| 315 | >.git/MERGE_RR.lock && |
| 316 | test_must_fail git -c rerere.lockTimeout=0 rebase --abort 2>err && |
| 317 | test_grep "Unable to create.*MERGE_RR\.lock" err && |
| 318 | test_path_is_dir .git/rebase-merge && |
| 319 | rm .git/MERGE_RR.lock && |
| 320 | git rebase --abort && |
| 321 | test_path_is_missing .git/rebase-merge |
| 322 | ' |
| 323 | |
| 324 | rerere_gc_custom_expiry_test () { |
| 325 | five_days="$1" right_now="$2" |
| 326 | test_expect_success "rerere gc with custom expiry ($five_days, $right_now)" ' |
| 327 | rm -fr .git/rr-cache && |
| 328 | rr=.git/rr-cache/$ZERO_OID && |
| 329 | mkdir -p "$rr" && |
| 330 | >"$rr/preimage" && |
| 331 | >"$rr/postimage" && |
| 332 | |
| 333 | two_days_ago=$((-2*86400)) && |
| 334 | test-tool chmtime =$two_days_ago "$rr/preimage" && |
| 335 | test-tool chmtime =$two_days_ago "$rr/postimage" && |
| 336 | |
| 337 | find .git/rr-cache -type f | sort >original && |
| 338 | |
| 339 | git -c "gc.rerereresolved=$five_days" \ |
| 340 | -c "gc.rerereunresolved=$five_days" rerere gc && |
| 341 | find .git/rr-cache -type f | sort >actual && |
| 342 | test_cmp original actual && |
| 343 | |
| 344 | git -c "gc.rerereresolved=$five_days" \ |
| 345 | -c "gc.rerereunresolved=$right_now" rerere gc && |
| 346 | find .git/rr-cache -type f | sort >actual && |
| 347 | test_cmp original actual && |
| 348 | |
| 349 | git -c "gc.rerereresolved=$right_now" \ |
| 350 | -c "gc.rerereunresolved=$right_now" rerere gc && |
| 351 | find .git/rr-cache -type f | sort >actual && |
| 352 | test_must_be_empty actual |
| 353 | ' |
| 354 | } |
| 355 | |
| 356 | rerere_gc_custom_expiry_test 5 0 |
| 357 | |
| 358 | rerere_gc_custom_expiry_test 5.days.ago now |
| 359 | |
| 360 | test_expect_success 'setup: file2 added differently in two branches' ' |
| 361 | git reset --hard && |
| 362 | |
| 363 | git checkout -b fourth && |
| 364 | echo Hallo >file2 && |
| 365 | git add file2 && |
| 366 | test_tick && |
| 367 | git commit -m version1 && |
| 368 | |
| 369 | git checkout third && |
| 370 | echo Bello >file2 && |
| 371 | git add file2 && |
| 372 | test_tick && |
| 373 | git commit -m version2 && |
| 374 | |
| 375 | test_must_fail git merge fourth && |
| 376 | echo Cello >file2 && |
| 377 | git add file2 && |
| 378 | git commit -m resolution |
| 379 | ' |
| 380 | |
| 381 | test_expect_success 'resolution was recorded properly' ' |
| 382 | echo Cello >expected && |
| 383 | |
| 384 | git reset --hard HEAD~2 && |
| 385 | git checkout -b fifth && |
| 386 | |
| 387 | echo Hallo >file3 && |
| 388 | git add file3 && |
| 389 | test_tick && |
| 390 | git commit -m version1 && |
| 391 | |
| 392 | git checkout third && |
| 393 | echo Bello >file3 && |
| 394 | git add file3 && |
| 395 | test_tick && |
| 396 | git commit -m version2 && |
| 397 | git tag version2 && |
| 398 | |
| 399 | test_must_fail git merge fifth && |
| 400 | test_cmp expected file3 && |
| 401 | test_must_fail git update-index --refresh |
| 402 | ' |
| 403 | |
| 404 | test_expect_success 'rerere.autoupdate' ' |
| 405 | git config rerere.autoupdate true && |
| 406 | git reset --hard && |
| 407 | git checkout version2 && |
| 408 | test_must_fail git merge fifth && |
| 409 | git update-index --refresh |
| 410 | ' |
| 411 | |
| 412 | test_expect_success 'merge --rerere-autoupdate' ' |
| 413 | test_might_fail git config --unset rerere.autoupdate && |
| 414 | git reset --hard && |
| 415 | git checkout version2 && |
| 416 | test_must_fail git merge --rerere-autoupdate fifth && |
| 417 | git update-index --refresh |
| 418 | ' |
| 419 | |
| 420 | test_expect_success 'merge --no-rerere-autoupdate' ' |
| 421 | headblob=$(git rev-parse version2:file3) && |
| 422 | mergeblob=$(git rev-parse fifth:file3) && |
| 423 | cat >expected <<-EOF && |
| 424 | 100644 $headblob 2 file3 |
| 425 | 100644 $mergeblob 3 file3 |
| 426 | EOF |
| 427 | |
| 428 | git config rerere.autoupdate true && |
| 429 | git reset --hard && |
| 430 | git checkout version2 && |
| 431 | test_must_fail git merge --no-rerere-autoupdate fifth && |
| 432 | git ls-files -u >actual && |
| 433 | test_cmp expected actual |
| 434 | ' |
| 435 | |
| 436 | test_expect_success 'set up an unresolved merge' ' |
| 437 | headblob=$(git rev-parse version2:file3) && |
| 438 | mergeblob=$(git rev-parse fifth:file3) && |
| 439 | cat >expected.unresolved <<-EOF && |
| 440 | 100644 $headblob 2 file3 |
| 441 | 100644 $mergeblob 3 file3 |
| 442 | EOF |
| 443 | |
| 444 | test_might_fail git config --unset rerere.autoupdate && |
| 445 | git reset --hard && |
| 446 | git checkout version2 && |
| 447 | ancestor=$(git merge-base version2 fifth) && |
| 448 | test_must_fail git merge-recursive "$ancestor" -- HEAD fifth && |
| 449 | |
| 450 | git ls-files --stage >failedmerge && |
| 451 | cp file3 file3.conflict && |
| 452 | |
| 453 | git ls-files -u >actual && |
| 454 | test_cmp expected.unresolved actual |
| 455 | ' |
| 456 | |
| 457 | test_expect_success 'explicit rerere' ' |
| 458 | test_might_fail git config --unset rerere.autoupdate && |
| 459 | git rm -fr --cached . && |
| 460 | git update-index --index-info <failedmerge && |
| 461 | cp file3.conflict file3 && |
| 462 | test_must_fail git update-index --refresh -q && |
| 463 | |
| 464 | git rerere && |
| 465 | git ls-files -u >actual && |
| 466 | test_cmp expected.unresolved actual |
| 467 | ' |
| 468 | |
| 469 | test_expect_success 'explicit rerere with autoupdate' ' |
| 470 | git config rerere.autoupdate true && |
| 471 | git rm -fr --cached . && |
| 472 | git update-index --index-info <failedmerge && |
| 473 | cp file3.conflict file3 && |
| 474 | test_must_fail git update-index --refresh -q && |
| 475 | |
| 476 | git rerere && |
| 477 | git update-index --refresh |
| 478 | ' |
| 479 | |
| 480 | test_expect_success 'explicit rerere --rerere-autoupdate overrides' ' |
| 481 | git config rerere.autoupdate false && |
| 482 | git rm -fr --cached . && |
| 483 | git update-index --index-info <failedmerge && |
| 484 | cp file3.conflict file3 && |
| 485 | git rerere && |
| 486 | git ls-files -u >actual1 && |
| 487 | |
| 488 | git rm -fr --cached . && |
| 489 | git update-index --index-info <failedmerge && |
| 490 | cp file3.conflict file3 && |
| 491 | git rerere --rerere-autoupdate && |
| 492 | git update-index --refresh && |
| 493 | |
| 494 | git rm -fr --cached . && |
| 495 | git update-index --index-info <failedmerge && |
| 496 | cp file3.conflict file3 && |
| 497 | git rerere --rerere-autoupdate --no-rerere-autoupdate && |
| 498 | git ls-files -u >actual2 && |
| 499 | |
| 500 | git rm -fr --cached . && |
| 501 | git update-index --index-info <failedmerge && |
| 502 | cp file3.conflict file3 && |
| 503 | git rerere --rerere-autoupdate --no-rerere-autoupdate --rerere-autoupdate && |
| 504 | git update-index --refresh && |
| 505 | |
| 506 | test_cmp expected.unresolved actual1 && |
| 507 | test_cmp expected.unresolved actual2 |
| 508 | ' |
| 509 | |
| 510 | test_expect_success 'rerere --no-no-rerere-autoupdate' ' |
| 511 | git rm -fr --cached . && |
| 512 | git update-index --index-info <failedmerge && |
| 513 | cp file3.conflict file3 && |
| 514 | test_must_fail git rerere --no-no-rerere-autoupdate 2>err && |
| 515 | test_grep [Uu]sage err && |
| 516 | test_must_fail git update-index --refresh |
| 517 | ' |
| 518 | |
| 519 | test_expect_success 'rerere -h' ' |
| 520 | git rerere -h >help && |
| 521 | test_grep [Uu]sage help |
| 522 | ' |
| 523 | |
| 524 | concat_insert () { |
| 525 | last=$1 |
| 526 | shift |
| 527 | cat early && printf "%s\n" "$@" && cat late "$last" |
| 528 | } |
| 529 | |
| 530 | count_pre_post () { |
| 531 | find .git/rr-cache/ -type f -name "preimage*" >actual && |
| 532 | test_line_count = "$1" actual && |
| 533 | find .git/rr-cache/ -type f -name "postimage*" >actual && |
| 534 | test_line_count = "$2" actual |
| 535 | } |
| 536 | |
| 537 | merge_conflict_resolve () { |
| 538 | git reset --hard && |
| 539 | test_must_fail git merge six.1 && |
| 540 | # Resolution is to replace 7 with 6.1 and 6.2 (i.e. take both) |
| 541 | concat_insert short 6.1 6.2 >file1 && |
| 542 | concat_insert long 6.1 6.2 >file2 |
| 543 | } |
| 544 | |
| 545 | test_expect_success 'multiple identical conflicts' ' |
| 546 | rm -fr .git/rr-cache && |
| 547 | mkdir .git/rr-cache && |
| 548 | git reset --hard && |
| 549 | |
| 550 | test_seq 1 6 >early && |
| 551 | >late && |
| 552 | test_seq 11 15 >short && |
| 553 | test_seq 111 120 >long && |
| 554 | concat_insert short >file1 && |
| 555 | concat_insert long >file2 && |
| 556 | git add file1 file2 && |
| 557 | git commit -m base && |
| 558 | git tag base && |
| 559 | git checkout -b six.1 && |
| 560 | concat_insert short 6.1 >file1 && |
| 561 | concat_insert long 6.1 >file2 && |
| 562 | git add file1 file2 && |
| 563 | git commit -m 6.1 && |
| 564 | git checkout -b six.2 HEAD^ && |
| 565 | concat_insert short 6.2 >file1 && |
| 566 | concat_insert long 6.2 >file2 && |
| 567 | git add file1 file2 && |
| 568 | git commit -m 6.2 && |
| 569 | |
| 570 | # At this point, six.1 and six.2 |
| 571 | # - derive from common ancestor that has two files |
| 572 | # 1...6 7 11..15 (file1) and 1...6 7 111..120 (file2) |
| 573 | # - six.1 replaces these 7s with 6.1 |
| 574 | # - six.2 replaces these 7s with 6.2 |
| 575 | |
| 576 | merge_conflict_resolve && |
| 577 | |
| 578 | # Check that rerere knows that file1 and file2 have conflicts |
| 579 | |
| 580 | printf "%s\n" file1 file2 >expect && |
| 581 | git ls-files -u | sed -e "s/^.* //" | sort -u >actual && |
| 582 | test_cmp expect actual && |
| 583 | |
| 584 | git rerere status | sort >actual && |
| 585 | test_cmp expect actual && |
| 586 | |
| 587 | git rerere remaining >actual && |
| 588 | test_cmp expect actual && |
| 589 | |
| 590 | count_pre_post 2 0 && |
| 591 | |
| 592 | # Pretend that the conflicts were made quite some time ago |
| 593 | test-tool chmtime -172800 $(find .git/rr-cache/ -type f) && |
| 594 | |
| 595 | # Unresolved entries have not expired yet |
| 596 | git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc && |
| 597 | count_pre_post 2 0 && |
| 598 | |
| 599 | # Unresolved entries have expired |
| 600 | git -c gc.rerereresolved=5 -c gc.rerereunresolved=1 rerere gc && |
| 601 | count_pre_post 0 0 && |
| 602 | |
| 603 | # Recreate the conflicted state |
| 604 | merge_conflict_resolve && |
| 605 | count_pre_post 2 0 && |
| 606 | |
| 607 | # Clear it |
| 608 | git rerere clear && |
| 609 | count_pre_post 0 0 && |
| 610 | |
| 611 | # Recreate the conflicted state |
| 612 | merge_conflict_resolve && |
| 613 | count_pre_post 2 0 && |
| 614 | |
| 615 | # We resolved file1 and file2 |
| 616 | git rerere && |
| 617 | git rerere remaining >actual && |
| 618 | test_must_be_empty actual && |
| 619 | |
| 620 | # We must have recorded both of them |
| 621 | count_pre_post 2 2 && |
| 622 | |
| 623 | # Now we should be able to resolve them both |
| 624 | git reset --hard && |
| 625 | test_must_fail git merge six.1 && |
| 626 | git rerere && |
| 627 | |
| 628 | git rerere remaining >actual && |
| 629 | test_must_be_empty actual && |
| 630 | |
| 631 | concat_insert short 6.1 6.2 >file1.expect && |
| 632 | concat_insert long 6.1 6.2 >file2.expect && |
| 633 | test_cmp file1.expect file1 && |
| 634 | test_cmp file2.expect file2 && |
| 635 | |
| 636 | # Forget resolution for file2 |
| 637 | git rerere forget file2 && |
| 638 | echo file2 >expect && |
| 639 | git rerere status >actual && |
| 640 | test_cmp expect actual && |
| 641 | count_pre_post 2 1 && |
| 642 | |
| 643 | # file2 already has correct resolution, so record it again |
| 644 | git rerere && |
| 645 | |
| 646 | # Pretend that the resolutions are old again |
| 647 | test-tool chmtime -172800 $(find .git/rr-cache/ -type f) && |
| 648 | |
| 649 | # Resolved entries have not expired yet |
| 650 | git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc && |
| 651 | |
| 652 | count_pre_post 2 2 && |
| 653 | |
| 654 | # Resolved entries have expired |
| 655 | git -c gc.rerereresolved=1 -c gc.rerereunresolved=5 rerere gc && |
| 656 | count_pre_post 0 0 |
| 657 | ' |
| 658 | |
| 659 | test_expect_success 'rerere with unexpected conflict markers does not crash' ' |
| 660 | git reset --hard && |
| 661 | |
| 662 | git checkout -b branch-1 main && |
| 663 | echo "bar" >test && |
| 664 | git add test && |
| 665 | git commit -q -m two && |
| 666 | |
| 667 | git reset --hard && |
| 668 | git checkout -b branch-2 main && |
| 669 | echo "foo" >test && |
| 670 | git add test && |
| 671 | git commit -q -a -m one && |
| 672 | |
| 673 | test_must_fail git merge branch-1 && |
| 674 | echo "<<<<<<< a" >test && |
| 675 | git rerere && |
| 676 | |
| 677 | git rerere clear |
| 678 | ' |
| 679 | |
| 680 | test_expect_success 'rerere with inner conflict markers' ' |
| 681 | git reset --hard && |
| 682 | |
| 683 | git checkout -b A main && |
| 684 | echo "bar" >test && |
| 685 | git add test && |
| 686 | git commit -q -m two && |
| 687 | echo "baz" >test && |
| 688 | git add test && |
| 689 | git commit -q -m three && |
| 690 | |
| 691 | git reset --hard && |
| 692 | git checkout -b B main && |
| 693 | echo "foo" >test && |
| 694 | git add test && |
| 695 | git commit -q -a -m one && |
| 696 | |
| 697 | test_must_fail git merge A~ && |
| 698 | git add test && |
| 699 | git commit -q -m "will solve conflicts later" && |
| 700 | test_must_fail git merge A && |
| 701 | |
| 702 | echo "resolved" >test && |
| 703 | git add test && |
| 704 | git commit -q -m "solved conflict" && |
| 705 | |
| 706 | echo "resolved" >expect && |
| 707 | |
| 708 | git reset --hard HEAD~~ && |
| 709 | test_must_fail git merge A~ && |
| 710 | git add test && |
| 711 | git commit -q -m "will solve conflicts later" && |
| 712 | test_must_fail git merge A && |
| 713 | cat test >actual && |
| 714 | test_cmp expect actual && |
| 715 | |
| 716 | git add test && |
| 717 | git commit -m "rerere solved conflict" && |
| 718 | git reset --hard HEAD~ && |
| 719 | test_must_fail git merge A && |
| 720 | cat test >actual && |
| 721 | test_cmp expect actual |
| 722 | ' |
| 723 | |
| 724 | test_expect_success 'setup simple stage 1 handling' ' |
| 725 | test_create_repo stage_1_handling && |
| 726 | ( |
| 727 | cd stage_1_handling && |
| 728 | |
| 729 | test_seq 1 10 >original && |
| 730 | git add original && |
| 731 | git commit -m original && |
| 732 | |
| 733 | git checkout -b A main && |
| 734 | git mv original A && |
| 735 | git commit -m "rename to A" && |
| 736 | |
| 737 | git checkout -b B main && |
| 738 | git mv original B && |
| 739 | git commit -m "rename to B" |
| 740 | ) |
| 741 | ' |
| 742 | |
| 743 | test_expect_success 'test simple stage 1 handling' ' |
| 744 | ( |
| 745 | cd stage_1_handling && |
| 746 | |
| 747 | git config rerere.enabled true && |
| 748 | git checkout A^0 && |
| 749 | test_must_fail git merge B^0 |
| 750 | ) |
| 751 | ' |
| 752 | |
| 753 | test_expect_success 'rerere does not crash with missing preimage' ' |
| 754 | git config rerere.enabled true && |
| 755 | |
| 756 | echo bar >test && |
| 757 | git add test && |
| 758 | git commit -m "one" && |
| 759 | git branch rerere_no_crash && |
| 760 | |
| 761 | echo foo >>test && |
| 762 | git add test && |
| 763 | git commit -m "two" && |
| 764 | |
| 765 | git checkout rerere_no_crash && |
| 766 | echo "bar" >>test && |
| 767 | git add test && |
| 768 | git commit -m "three" && |
| 769 | |
| 770 | test_must_fail git rebase main && |
| 771 | rm .git/rr-cache/*/preimage && |
| 772 | git rebase --abort |
| 773 | ' |
| 774 | |
| 775 | test_expect_success 'rerere does not crash with unmatched conflict marker' ' |
| 776 | git config rerere.enabled true && |
| 777 | |
| 778 | echo bar >test && |
| 779 | git add test && |
| 780 | git commit -m "one" && |
| 781 | git branch rerere_no_preimage && |
| 782 | |
| 783 | cat >test <<-EOF && |
| 784 | test |
| 785 | bar |
| 786 | foobar |
| 787 | EOF |
| 788 | git add test && |
| 789 | git commit -m "two" && |
| 790 | |
| 791 | git checkout rerere_no_preimage && |
| 792 | echo "bar" >>test && |
| 793 | git add test && |
| 794 | git commit -m "three" && |
| 795 | |
| 796 | cat >test <<-EOF && |
| 797 | foobar |
| 798 | bar |
| 799 | bar |
| 800 | EOF |
| 801 | git add test && |
| 802 | git commit -m "four" && |
| 803 | |
| 804 | test_must_fail git rebase main && |
| 805 | cat >test <<-EOF && |
| 806 | test |
| 807 | bar |
| 808 | <<<<<<< HEAD |
| 809 | foobar |
| 810 | bar |
| 811 | EOF |
| 812 | git add test && |
| 813 | test_must_fail git rebase --continue |
| 814 | ' |
| 815 | |
| 816 | test_expect_success 'rerere preserves conflicts when driver output is unreadable' ' |
| 817 | test_create_repo unreadable-output && |
| 818 | ( |
| 819 | cd unreadable-output && |
| 820 | git config rerere.enabled true && |
| 821 | git config rerere.autoupdate true && |
| 822 | write_script merge-driver <<-\EOF && |
| 823 | git merge-file "$@" |
| 824 | status=$? |
| 825 | if test -f fail-read |
| 826 | then |
| 827 | rm "$1" || exit 1 |
| 828 | fi |
| 829 | exit "$status" |
| 830 | EOF |
| 831 | git config merge.unreadable.driver "./merge-driver %A %O %B" && |
| 832 | echo "file merge=unreadable" >.gitattributes && |
| 833 | test_commit base file base && |
| 834 | git checkout -b one && |
| 835 | test_commit --no-tag one file one && |
| 836 | git checkout -b two base && |
| 837 | test_commit --no-tag two file two && |
| 838 | |
| 839 | # Teach rerere a resolution while the driver works normally. |
| 840 | test_must_fail git merge one && |
| 841 | echo resolved >file && |
| 842 | git rerere && |
| 843 | git merge --abort && |
| 844 | |
| 845 | # Recreate the conflict without replaying the resolution yet. |
| 846 | test_must_fail git -c rerere.enabled=false merge one && |
| 847 | |
| 848 | # We will expect the same conflicted content after rerere fails |
| 849 | # below. |
| 850 | cp file expect && |
| 851 | git ls-files -u >expect-index && |
| 852 | test_file_not_empty expect-index && |
| 853 | |
| 854 | # Now we try rerere again, but the merge driver will cause the |
| 855 | # read to fail. |
| 856 | >fail-read && |
| 857 | git rerere 2>err && |
| 858 | test_grep "Could not stat" err && |
| 859 | |
| 860 | # And we expect the conflicted state. |
| 861 | test_cmp expect file && |
| 862 | git ls-files -u >actual-index && |
| 863 | test_cmp expect-index actual-index |
| 864 | ) |
| 865 | ' |
| 866 | |
| 867 | test_done |