Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t7201-co.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t7201-co.sh` 903 lines ยท 22084 bytes Raw Blame History 1 #!/bin/sh 2 # 3 # Copyright (c) 2006 Junio C Hamano 4 # 5 6 test_description='git checkout tests. 7 8 Creates main, forks renamer and side branches from it. 9 Test switching across them. 10 11 ! [main] Initial A one, A two 12 * [renamer] Renamer R one->uno, M two 13 ! [side] Side M one, D two, A three 14 ! [simple] Simple D one, M two 15 ---- 16 + [simple] Simple D one, M two 17 + [side] Side M one, D two, A three 18 * [renamer] Renamer R one->uno, M two 19 +*++ [main] Initial A one, A two 20 21 ' 22 23 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main 24 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 25 26 . ./test-lib.sh 27 28 test_tick 29 30 fill () { 31 for i 32 do 33 echo "$i" 34 done 35 } 36 37 38 test_expect_success setup ' 39 fill x y z >same && 40 fill 1 2 3 4 5 6 7 8 >one && 41 fill a b c d e >two && 42 git add same one two && 43 git commit -m "Initial A one, A two" && 44 45 git checkout -b renamer && 46 rm -f one && 47 fill 1 3 4 5 6 7 8 >uno && 48 git add uno && 49 fill a b c d e f >two && 50 git commit -a -m "Renamer R one->uno, M two" && 51 52 git checkout -b side main && 53 fill 1 2 3 4 5 6 7 >one && 54 fill A B C D E >three && 55 rm -f two && 56 git update-index --add --remove one two three && 57 git commit -m "Side M one, D two, A three" && 58 59 git checkout -b simple main && 60 rm -f one && 61 fill a c e >two && 62 git commit -a -m "Simple D one, M two" && 63 64 git checkout main 65 ' 66 67 test_expect_success 'checkout from non-existing branch' ' 68 git checkout -b delete-me main && 69 git update-ref -d --no-deref refs/heads/delete-me && 70 test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && 71 git checkout main && 72 test refs/heads/main = "$(git symbolic-ref HEAD)" 73 ' 74 75 test_expect_success 'checkout with dirty tree without -m' ' 76 fill 0 1 2 3 4 5 6 7 8 >one && 77 if git checkout side 78 then 79 echo Not happy 80 false 81 else 82 echo "happy - failed correctly" 83 fi 84 ' 85 86 test_expect_success 'checkout with unrelated dirty tree without -m' ' 87 git checkout -f main && 88 fill 0 1 2 3 4 5 6 7 8 >same && 89 cp same kept && 90 git checkout side >messages && 91 test_cmp same kept && 92 printf "M\t%s\n" same >messages.expect && 93 test_cmp messages.expect messages 94 ' 95 96 test_expect_success 'checkout -m with dirty tree' ' 97 git checkout -f main && 98 git clean -f && 99 100 fill 0 1 2 3 4 5 6 7 8 >one && 101 git checkout -m side >messages && 102 test_path_is_missing .git/MERGE_LABELS && 103 104 test "$(git symbolic-ref HEAD)" = "refs/heads/side" && 105 106 cat >expect.messages <<-\EOF && 107 The following paths have local changes: 108 M one 109 EOF 110 test_cmp expect.messages messages && 111 112 fill "M one" "A three" "D two" >expect.main && 113 git diff --name-status main >current.main && 114 test_cmp expect.main current.main && 115 116 fill "M one" >expect.side && 117 git diff --name-status side >current.side && 118 test_cmp expect.side current.side && 119 120 git diff --cached >current.index && 121 test_must_be_empty current.index 122 ' 123 124 test_expect_success 'checkout -m with dirty tree, renamed' ' 125 git checkout -f main && git clean -f && 126 127 fill 1 2 3 4 5 7 8 >one && 128 if git checkout renamer 129 then 130 echo Not happy 131 false 132 else 133 echo "happy - failed correctly" 134 fi && 135 136 git checkout -m renamer && 137 fill 1 3 4 5 7 8 >expect && 138 test_cmp expect uno && 139 ! test -f one && 140 git diff --cached >current && 141 test_must_be_empty current 142 ' 143 144 test_expect_success 'checkout -m with merge conflict' ' 145 git checkout -f main && git clean -f && 146 147 fill 1 T 3 4 5 6 S 8 >one && 148 if git checkout renamer 149 then 150 echo Not happy 151 false 152 else 153 echo "happy - failed correctly" 154 fi && 155 156 git checkout -m renamer && 157 158 git diff main:one :3:uno | 159 sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current && 160 fill d2 aT d7 aS >expect && 161 test_cmp expect current && 162 git diff --cached two >current && 163 test_must_be_empty current 164 ' 165 166 test_expect_success 'format of merge conflict from checkout -m' ' 167 git checkout -f main && 168 git clean -f && 169 170 fill b d >two && 171 git checkout -m simple && 172 173 git ls-files >current && 174 fill same two two two >expect && 175 test_cmp expect current && 176 177 cat <<-EOF >expect && 178 <<<<<<< simple 179 a 180 c 181 e 182 ======= 183 b 184 d 185 >>>>>>> local 186 EOF 187 test_cmp expect two && 188 189 test_path_is_file .git/MERGE_LABELS && 190 191 git checkout --conflict=diff3 two && 192 cat >expect <<-\EOF && 193 <<<<<<< simple 194 a 195 c 196 e 197 ||||||| main 198 a 199 b 200 c 201 d 202 e 203 ======= 204 b 205 d 206 >>>>>>> local 207 EOF 208 test_cmp expect two 209 ' 210 211 test_expect_success 'checkout --merge --conflict=diff3 ' ' 212 git checkout -f main && 213 git reset --hard && 214 git clean -f && 215 216 fill b d >two && 217 git checkout --merge --conflict=diff3 simple && 218 219 cat <<-EOF >expect && 220 <<<<<<< simple 221 a 222 c 223 e 224 ||||||| main 225 a 226 b 227 c 228 d 229 e 230 ======= 231 b 232 d 233 >>>>>>> local 234 EOF 235 test_cmp expect two 236 ' 237 238 test_expect_success 'checkout -m with mixed staged and unstaged changes' ' 239 git checkout -f main && 240 git clean -f && 241 242 fill 0 x y z >same && 243 git add same && 244 fill 1 2 3 4 5 6 7 >one && 245 git checkout -m side >actual 2>&1 && 246 test_grep "Applied autostash" actual && 247 fill 0 x y z >expect && 248 test_cmp expect same && 249 fill 1 2 3 4 5 6 7 >expect && 250 test_cmp expect one 251 ' 252 253 test_expect_success 'checkout -m creates a recoverable stash on conflict' ' 254 git checkout -f main && 255 git clean -f && 256 257 fill 1 2 3 4 5 >one && 258 test_must_fail git checkout side 2>stderr && 259 test_grep "Your local changes" stderr && 260 git checkout -m side >actual 2>&1 && 261 cat >expect <<-EOF && 262 Your local changes are stashed, however applying them 263 resulted in conflicts. You can either resolve the conflicts 264 and then discard the stash with "git stash drop", or, if you 265 do not want to resolve them now, run "git reset --hard" and 266 apply the local changes later by running "git stash pop". 267 268 Switched to branch ${SQ}side${SQ} 269 The following paths have local changes: 270 M one 271 EOF 272 test_cmp expect actual && 273 git log -p -1 --format="%gs%n%B" -g --diff-merges=1 refs/stash >actual && 274 sed /^index/d actual >actual.trimmed && 275 cat >expect <<-EOF && 276 autostash while switching to ${SQ}side${SQ} 277 On main: autostash while switching to ${SQ}side${SQ} 278 279 diff --git a/one b/one 280 --- a/one 281 +++ b/one 282 @@ -3,6 +3,3 @@ 283 3 284 4 285 5 286 -6 287 -7 288 -8 289 EOF 290 test_cmp expect actual.trimmed && 291 git stash drop && 292 git reset --hard 293 ' 294 295 test_expect_success 'checkout -m which would overwrite untracked file' ' 296 git checkout -f --detach main && 297 test_commit another-file && 298 git checkout HEAD^ && 299 >another-file.t && 300 fill 1 2 3 4 5 >one && 301 test_must_fail git checkout -m @{-1} 2>err && 302 q_to_tab >expect <<-\EOF && 303 error: The following untracked working tree files would be overwritten by checkout: 304 Qanother-file.t 305 Please move or remove them before you switch branches. 306 Aborting 307 Applied autostash. 308 EOF 309 test_cmp expect err 310 ' 311 312 test_expect_success 'switch to another branch while carrying a deletion' ' 313 git checkout -f main && 314 git reset --hard && 315 git clean -f && 316 git rm two && 317 318 test_must_fail git checkout simple 2>errs && 319 test_grep overwritten errs && 320 321 test_must_fail git read-tree --quiet -m -u HEAD simple 2>errs && 322 test_must_be_empty errs 323 ' 324 325 test_expect_success 'checkout to detach HEAD (with advice declined)' ' 326 git config set advice.detachedHead false && 327 rev=$(git rev-parse --short renamer^) && 328 git checkout -f renamer && 329 git clean -f && 330 git checkout renamer^ 2>messages && 331 test_grep "HEAD is now at $rev" messages && 332 test_line_count = 1 messages && 333 H=$(git rev-parse --verify HEAD) && 334 M=$(git show-ref -s --verify refs/heads/main) && 335 test "z$H" = "z$M" && 336 if git symbolic-ref HEAD >/dev/null 2>&1 337 then 338 echo "OOPS, HEAD is still symbolic???" 339 false 340 else 341 : happy 342 fi 343 ' 344 345 test_expect_success 'checkout to detach HEAD' ' 346 git config set advice.detachedHead true && 347 rev=$(git rev-parse --short renamer^) && 348 git checkout -f renamer && 349 git clean -f && 350 git checkout renamer^ 2>messages && 351 test_grep "HEAD is now at $rev" messages && 352 test_line_count -gt 1 messages && 353 H=$(git rev-parse --verify HEAD) && 354 M=$(git show-ref -s --verify refs/heads/main) && 355 test "z$H" = "z$M" && 356 if git symbolic-ref HEAD >/dev/null 2>&1 357 then 358 echo "OOPS, HEAD is still symbolic???" 359 false 360 else 361 : happy 362 fi 363 ' 364 365 test_expect_success 'checkout to detach HEAD with branchname^' ' 366 git checkout -f main && 367 git clean -f && 368 git checkout renamer^ && 369 H=$(git rev-parse --verify HEAD) && 370 M=$(git show-ref -s --verify refs/heads/main) && 371 test "z$H" = "z$M" && 372 if git symbolic-ref HEAD >/dev/null 2>&1 373 then 374 echo "OOPS, HEAD is still symbolic???" 375 false 376 else 377 : happy 378 fi 379 ' 380 381 test_expect_success 'checkout to detach HEAD with :/message' ' 382 git checkout -f main && 383 git clean -f && 384 git checkout ":/Initial" && 385 H=$(git rev-parse --verify HEAD) && 386 M=$(git show-ref -s --verify refs/heads/main) && 387 test "z$H" = "z$M" && 388 if git symbolic-ref HEAD >/dev/null 2>&1 389 then 390 echo "OOPS, HEAD is still symbolic???" 391 false 392 else 393 : happy 394 fi 395 ' 396 397 test_expect_success 'checkout to detach HEAD with HEAD^0' ' 398 git checkout -f main && 399 git clean -f && 400 git checkout HEAD^0 && 401 H=$(git rev-parse --verify HEAD) && 402 M=$(git show-ref -s --verify refs/heads/main) && 403 test "z$H" = "z$M" && 404 if git symbolic-ref HEAD >/dev/null 2>&1 405 then 406 echo "OOPS, HEAD is still symbolic???" 407 false 408 else 409 : happy 410 fi 411 ' 412 413 test_expect_success 'checkout with ambiguous tag/branch names' ' 414 git tag both side && 415 git branch both main && 416 git reset --hard && 417 git checkout main && 418 419 git checkout both && 420 H=$(git rev-parse --verify HEAD) && 421 M=$(git show-ref -s --verify refs/heads/main) && 422 test "z$H" = "z$M" && 423 name=$(git symbolic-ref HEAD 2>/dev/null) && 424 test "z$name" = zrefs/heads/both 425 ' 426 427 test_expect_success 'checkout with ambiguous tag/branch names' ' 428 git reset --hard && 429 git checkout main && 430 431 git tag frotz side && 432 git branch frotz main && 433 git reset --hard && 434 git checkout main && 435 436 git checkout tags/frotz && 437 H=$(git rev-parse --verify HEAD) && 438 S=$(git show-ref -s --verify refs/heads/side) && 439 test "z$H" = "z$S" && 440 if name=$(git symbolic-ref HEAD 2>/dev/null) 441 then 442 echo "Bad -- should have detached" 443 false 444 else 445 : happy 446 fi 447 ' 448 449 test_expect_success 'switch branches while in subdirectory' ' 450 git reset --hard && 451 git checkout main && 452 453 mkdir subs && 454 git -C subs checkout side && 455 ! test -f subs/one && 456 rm -fr subs 457 ' 458 459 test_expect_success 'checkout specific path while in subdirectory' ' 460 git reset --hard && 461 git checkout side && 462 mkdir subs && 463 >subs/bero && 464 git add subs/bero && 465 git commit -m "add subs/bero" && 466 467 git checkout main && 468 mkdir -p subs && 469 git -C subs checkout side -- bero && 470 test -f subs/bero 471 ' 472 473 test_expect_success 'checkout w/--track sets up tracking' ' 474 git config branch.autosetupmerge false && 475 git checkout main && 476 git checkout --track -b track1 && 477 test "$(git config branch.track1.remote)" && 478 test "$(git config branch.track1.merge)" 479 ' 480 481 test_expect_success 'checkout w/autosetupmerge=always sets up tracking' ' 482 test_when_finished git config branch.autosetupmerge false && 483 git config branch.autosetupmerge always && 484 git checkout main && 485 git checkout -b track2 && 486 test "$(git config branch.track2.remote)" && 487 test "$(git config branch.track2.merge)" 488 ' 489 490 test_expect_success 'checkout w/--track from non-branch HEAD fails' ' 491 git checkout main^0 && 492 test_must_fail git symbolic-ref HEAD && 493 test_must_fail git checkout --track -b track && 494 test_must_fail git rev-parse --verify track && 495 test_must_fail git symbolic-ref HEAD && 496 test "z$(git rev-parse main^0)" = "z$(git rev-parse HEAD)" 497 ' 498 499 test_expect_success 'checkout w/--track from tag fails' ' 500 git checkout main^0 && 501 test_must_fail git symbolic-ref HEAD && 502 test_must_fail git checkout --track -b track frotz && 503 test_must_fail git rev-parse --verify track && 504 test_must_fail git symbolic-ref HEAD && 505 test "z$(git rev-parse main^0)" = "z$(git rev-parse HEAD)" 506 ' 507 508 test_expect_success 'detach a symbolic link HEAD' ' 509 git checkout main && 510 git config --bool core.prefersymlinkrefs yes && 511 git checkout side && 512 git checkout main && 513 it=$(git symbolic-ref HEAD) && 514 test "z$it" = zrefs/heads/main && 515 here=$(git rev-parse --verify refs/heads/main) && 516 git checkout side^ && 517 test "z$(git rev-parse --verify refs/heads/main)" = "z$here" 518 ' 519 520 test_expect_success 'checkout with --track fakes a sensible -b ' ' 521 git config remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*" && 522 git update-ref refs/remotes/origin/koala/bear renamer && 523 524 git checkout --track origin/koala/bear && 525 test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && 526 test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" && 527 528 git checkout main && git branch -D koala/bear && 529 530 git checkout --track refs/remotes/origin/koala/bear && 531 test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && 532 test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" && 533 534 git checkout main && git branch -D koala/bear && 535 536 git checkout --track remotes/origin/koala/bear && 537 test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && 538 test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" 539 ' 540 541 test_expect_success 'checkout with --track, but without -b, fails with too short tracked name' ' 542 test_must_fail git checkout --track renamer 543 ' 544 545 setup_conflicting_index () { 546 rm -f .git/index && 547 O=$(echo original | git hash-object -w --stdin) && 548 A=$(echo ourside | git hash-object -w --stdin) && 549 B=$(echo theirside | git hash-object -w --stdin) && 550 ( 551 echo "100644 $A 0 fild" && 552 echo "100644 $O 1 file" && 553 echo "100644 $A 2 file" && 554 echo "100644 $B 3 file" && 555 echo "100644 $A 0 filf" 556 ) | git update-index --index-info 557 } 558 559 test_expect_success 'checkout an unmerged path should fail' ' 560 setup_conflicting_index && 561 echo "none of the above" >sample && 562 cat sample >fild && 563 cat sample >file && 564 cat sample >filf && 565 test_must_fail git checkout fild file filf && 566 test_cmp sample fild && 567 test_cmp sample filf && 568 test_cmp sample file 569 ' 570 571 test_expect_success 'checkout with an unmerged path can be ignored' ' 572 setup_conflicting_index && 573 echo "none of the above" >sample && 574 echo ourside >expect && 575 cat sample >fild && 576 cat sample >file && 577 cat sample >filf && 578 git checkout -f fild file filf && 579 test_cmp expect fild && 580 test_cmp expect filf && 581 test_cmp sample file 582 ' 583 584 test_expect_success 'checkout unmerged stage' ' 585 setup_conflicting_index && 586 echo "none of the above" >sample && 587 echo ourside >expect && 588 cat sample >fild && 589 cat sample >file && 590 cat sample >filf && 591 git checkout --ours . && 592 test_cmp expect fild && 593 test_cmp expect filf && 594 test_cmp expect file && 595 git checkout --theirs file && 596 test ztheirside = "z$(cat file)" 597 ' 598 599 test_expect_success 'checkout --ours is incompatible with switching' ' 600 test_must_fail git checkout --ours 2>error && 601 test_grep "needs the paths to check out" error && 602 603 test_must_fail git checkout --ours HEAD 2>error && 604 test_grep "cannot be used with switching" error && 605 606 test_must_fail git checkout --ours main 2>error && 607 test_grep "cannot be used with switching" error && 608 609 git checkout --ours file 610 ' 611 612 test_expect_success 'checkout path with --merge from tree-ish is a no-no' ' 613 setup_conflicting_index && 614 test_must_fail git checkout -m HEAD -- file 615 ' 616 617 test_expect_success 'checkout with --merge' ' 618 setup_conflicting_index && 619 echo "none of the above" >sample && 620 echo ourside >expect && 621 cat sample >fild && 622 cat sample >file && 623 cat sample >filf && 624 git checkout -m -- fild file filf && 625 ( 626 echo "<<<<<<< ours" && 627 echo ourside && 628 echo "=======" && 629 echo theirside && 630 echo ">>>>>>> theirs" 631 ) >merged && 632 test_cmp expect fild && 633 test_cmp expect filf && 634 test_cmp merged file 635 ' 636 637 test_expect_success 'checkout -m works after (mistaken) resolution' ' 638 setup_conflicting_index && 639 echo "none of the above" >sample && 640 cat sample >fild && 641 cat sample >file && 642 cat sample >filf && 643 # resolve to something 644 git add file && 645 git checkout --merge -- fild file filf && 646 { 647 echo "<<<<<<< ours" && 648 echo ourside && 649 echo "=======" && 650 echo theirside && 651 echo ">>>>>>> theirs" 652 } >merged && 653 test_cmp expect fild && 654 test_cmp expect filf && 655 test_cmp merged file 656 ' 657 658 test_expect_success 'checkout -m works after (mistaken) resolution to remove' ' 659 setup_conflicting_index && 660 echo "none of the above" >sample && 661 cat sample >fild && 662 cat sample >file && 663 cat sample >filf && 664 # resolve to remove 665 git rm file && 666 git checkout --merge -- fild file filf && 667 { 668 echo "<<<<<<< ours" && 669 echo ourside && 670 echo "=======" && 671 echo theirside && 672 echo ">>>>>>> theirs" 673 } >merged && 674 test_cmp expect fild && 675 test_cmp expect filf && 676 test_cmp merged file 677 ' 678 679 test_expect_success 'checkout with --merge, in diff3 -m style' ' 680 git config merge.conflictstyle diff3 && 681 setup_conflicting_index && 682 echo "none of the above" >sample && 683 echo ourside >expect && 684 cat sample >fild && 685 cat sample >file && 686 cat sample >filf && 687 git checkout -m -- fild file filf && 688 ( 689 echo "<<<<<<< ours" && 690 echo ourside && 691 echo "||||||| base" && 692 echo original && 693 echo "=======" && 694 echo theirside && 695 echo ">>>>>>> theirs" 696 ) >merged && 697 test_cmp expect fild && 698 test_cmp expect filf && 699 test_cmp merged file 700 ' 701 702 test_expect_success 'checkout --conflict=merge, overriding config' ' 703 git config merge.conflictstyle diff3 && 704 setup_conflicting_index && 705 echo "none of the above" >sample && 706 echo ourside >expect && 707 cat sample >fild && 708 cat sample >file && 709 cat sample >filf && 710 git checkout --conflict=merge -- fild file filf && 711 ( 712 echo "<<<<<<< ours" && 713 echo ourside && 714 echo "=======" && 715 echo theirside && 716 echo ">>>>>>> theirs" 717 ) >merged && 718 test_cmp expect fild && 719 test_cmp expect filf && 720 test_cmp merged file 721 ' 722 723 test_expect_success 'checkout --conflict=diff3' ' 724 test_unconfig merge.conflictstyle && 725 setup_conflicting_index && 726 echo "none of the above" >sample && 727 echo ourside >expect && 728 cat sample >fild && 729 cat sample >file && 730 cat sample >filf && 731 git checkout --conflict=diff3 -- fild file filf && 732 ( 733 echo "<<<<<<< ours" && 734 echo ourside && 735 echo "||||||| base" && 736 echo original && 737 echo "=======" && 738 echo theirside && 739 echo ">>>>>>> theirs" 740 ) >merged && 741 test_cmp expect fild && 742 test_cmp expect filf && 743 test_cmp merged file 744 ' 745 746 test_expect_success 'checkout --conflict=diff3 --no-conflict does not merge' ' 747 setup_conflicting_index && 748 echo "none of the above" >expect && 749 cat expect >fild && 750 cat expect >file && 751 test_must_fail git checkout --conflict=diff3 --no-conflict -- fild file 2>err && 752 test_cmp expect file && 753 test_cmp expect fild && 754 echo "error: path ${SQ}file${SQ} is unmerged" >expect && 755 test_cmp expect err 756 ' 757 758 test_expect_success 'checkout --conflict=diff3 --no-merge does not merge' ' 759 setup_conflicting_index && 760 echo "none of the above" >expect && 761 cat expect >fild && 762 cat expect >file && 763 test_must_fail git checkout --conflict=diff3 --no-merge -- fild file 2>err && 764 test_cmp expect file && 765 test_cmp expect fild && 766 echo "error: path ${SQ}file${SQ} is unmerged" >expect && 767 test_cmp expect err 768 ' 769 770 test_expect_success 'checkout --no-merge --conflict=diff3 does merge' ' 771 setup_conflicting_index && 772 echo "none of the above" >fild && 773 echo "none of the above" >file && 774 git checkout --no-merge --conflict=diff3 -- fild file && 775 echo "ourside" >expect && 776 test_cmp expect fild && 777 cat >expect <<-\EOF && 778 <<<<<<< ours 779 ourside 780 ||||||| base 781 original 782 ======= 783 theirside 784 >>>>>>> theirs 785 EOF 786 test_cmp expect file 787 ' 788 789 test_expect_success 'checkout --merge --conflict=diff3 --no-conflict does merge' ' 790 setup_conflicting_index && 791 echo "none of the above" >fild && 792 echo "none of the above" >file && 793 git checkout --merge --conflict=diff3 --no-conflict -- fild file && 794 echo "ourside" >expect && 795 test_cmp expect fild && 796 cat >expect <<-\EOF && 797 <<<<<<< ours 798 ourside 799 ======= 800 theirside 801 >>>>>>> theirs 802 EOF 803 test_cmp expect file 804 ' 805 806 test_expect_success 'checkout with invalid conflict style' ' 807 test_must_fail git checkout --conflict=bad 2>actual -- file && 808 echo "error: unknown conflict style ${SQ}bad${SQ}" >expect && 809 test_cmp expect actual 810 ' 811 812 test_expect_success 'failing checkout -b should not break working tree' ' 813 git clean -fd && # Remove untracked files in the way 814 git reset --hard main && 815 git symbolic-ref HEAD refs/heads/main && 816 test_must_fail git checkout -b renamer side^ && 817 test $(git symbolic-ref HEAD) = refs/heads/main && 818 git diff --exit-code && 819 git diff --cached --exit-code 820 ' 821 822 test_expect_success 'switch out of non-branch' ' 823 git reset --hard main && 824 git checkout main^0 && 825 echo modified >one && 826 test_must_fail git checkout renamer 2>error.log && 827 test_grep ! "^Previous HEAD" error.log 828 ' 829 830 ( 831 echo "#!$SHELL_PATH" 832 cat <<\EOF 833 O=$1 A=$2 B=$3 834 cat "$A" >.tmp 835 exec >"$A" 836 echo '<<<<<<< filfre-theirs' 837 cat "$B" 838 echo '||||||| filfre-common' 839 cat "$O" 840 echo '=======' 841 cat ".tmp" 842 echo '>>>>>>> filfre-ours' 843 rm -f .tmp 844 exit 1 845 EOF 846 ) >filfre.sh 847 chmod +x filfre.sh 848 849 test_expect_success 'custom merge driver with checkout -m' ' 850 git reset --hard && 851 852 git config merge.filfre.driver "./filfre.sh %O %A %B" && 853 git config merge.filfre.name "Feel-free merge driver" && 854 git config merge.filfre.recursive binary && 855 echo "arm merge=filfre" >.gitattributes && 856 857 git checkout -b left && 858 echo neutral >arm && 859 git add arm .gitattributes && 860 test_tick && 861 git commit -m neutral && 862 git branch right && 863 864 echo left >arm && 865 test_tick && 866 git commit -a -m left && 867 git checkout right && 868 869 echo right >arm && 870 test_tick && 871 git commit -a -m right && 872 873 test_must_fail git merge left && 874 ( 875 for t in filfre-common left right 876 do 877 test_grep $t arm || exit 1 878 done 879 ) && 880 881 mv arm expect && 882 git checkout -m arm && 883 test_cmp expect arm 884 ' 885 886 test_expect_success 'tracking info copied with autoSetupMerge=inherit' ' 887 git reset --hard main && 888 # default config does not copy tracking info 889 git checkout -b foo-no-inherit koala/bear && 890 test_cmp_config "" --default "" branch.foo-no-inherit.remote && 891 test_cmp_config "" --default "" branch.foo-no-inherit.merge && 892 # with autoSetupMerge=inherit, we copy tracking info from koala/bear 893 test_config branch.autoSetupMerge inherit && 894 git checkout -b foo koala/bear && 895 test_cmp_config origin branch.foo.remote && 896 test_cmp_config refs/heads/koala/bear branch.foo.merge && 897 # no tracking info to inherit from main 898 git checkout -b main2 main && 899 test_cmp_config "" --default "" branch.main2.remote && 900 test_cmp_config "" --default "" branch.main2.merge 901 ' 902 903 test_done