| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='Merge-recursive ours and theirs variants' |
| 4 | GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main |
| 5 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 6 | |
| 7 | . ./test-lib.sh |
| 8 | |
| 9 | test_expect_success setup ' |
| 10 | test_write_lines 1 2 3 4 5 6 7 8 9 >file && |
| 11 | git add file && |
| 12 | cp file elif && |
| 13 | git commit -m initial && |
| 14 | |
| 15 | sed -e "s/1/one/" -e "s/9/nine/" >file <elif && |
| 16 | git commit -a -m ours && |
| 17 | |
| 18 | git checkout -b side HEAD^ && |
| 19 | |
| 20 | sed -e "s/9/nueve/" >file <elif && |
| 21 | git commit -a -m theirs && |
| 22 | |
| 23 | git checkout main^0 |
| 24 | ' |
| 25 | |
| 26 | test_expect_success 'plain recursive - should conflict' ' |
| 27 | git reset --hard main && |
| 28 | test_must_fail git merge -s recursive side && |
| 29 | test_grep nine file && |
| 30 | test_grep nueve file && |
| 31 | test_grep ! 9 file && |
| 32 | test_grep one file && |
| 33 | test_grep ! 1 file |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'recursive favouring theirs' ' |
| 37 | git reset --hard main && |
| 38 | git merge -s recursive -Xtheirs side && |
| 39 | test_grep ! nine file && |
| 40 | test_grep nueve file && |
| 41 | test_grep ! 9 file && |
| 42 | test_grep one file && |
| 43 | test_grep ! 1 file |
| 44 | ' |
| 45 | |
| 46 | test_expect_success 'recursive favouring ours' ' |
| 47 | git reset --hard main && |
| 48 | git merge -s recursive -X ours side && |
| 49 | test_grep nine file && |
| 50 | test_grep ! nueve file && |
| 51 | test_grep ! 9 file && |
| 52 | test_grep one file && |
| 53 | test_grep ! 1 file |
| 54 | ' |
| 55 | |
| 56 | test_expect_success 'binary file with -Xours/-Xtheirs' ' |
| 57 | echo file binary >.gitattributes && |
| 58 | |
| 59 | git reset --hard main && |
| 60 | git merge -s recursive -X theirs side && |
| 61 | git diff --exit-code side HEAD -- file && |
| 62 | |
| 63 | git reset --hard main && |
| 64 | git merge -s recursive -X ours side && |
| 65 | git diff --exit-code main HEAD -- file |
| 66 | ' |
| 67 | |
| 68 | test_expect_success 'pull passes -X to underlying merge' ' |
| 69 | git reset --hard main && git pull --no-rebase -s recursive -Xours . side && |
| 70 | git reset --hard main && git pull --no-rebase -s recursive -X ours . side && |
| 71 | git reset --hard main && git pull --no-rebase -s recursive -Xtheirs . side && |
| 72 | git reset --hard main && git pull --no-rebase -s recursive -X theirs . side && |
| 73 | git reset --hard main && test_must_fail git pull --no-rebase -s recursive -X bork . side |
| 74 | ' |
| 75 | |
| 76 | test_expect_success SYMLINKS 'symlink with -Xours/-Xtheirs' ' |
| 77 | git reset --hard main && |
| 78 | git checkout -b two main && |
| 79 | ln -s target-zero link && |
| 80 | git add link && |
| 81 | git commit -m "add link pointing to zero" && |
| 82 | |
| 83 | ln -f -s target-two link && |
| 84 | git commit -m "add link pointing to two" link && |
| 85 | |
| 86 | git checkout -b one HEAD^ && |
| 87 | ln -f -s target-one link && |
| 88 | git commit -m "add link pointing to one" link && |
| 89 | |
| 90 | # we expect symbolic links not to resolve automatically, of course |
| 91 | git checkout one^0 && |
| 92 | test_must_fail git merge -s recursive two && |
| 93 | |
| 94 | # favor theirs to resolve to target-two? |
| 95 | git reset --hard && |
| 96 | git checkout one^0 && |
| 97 | git merge -s recursive -X theirs two && |
| 98 | git diff --exit-code two HEAD link && |
| 99 | |
| 100 | # favor ours to resolve to target-one? |
| 101 | git reset --hard && |
| 102 | git checkout one^0 && |
| 103 | git merge -s recursive -X ours two && |
| 104 | git diff --exit-code one HEAD link |
| 105 | |
| 106 | ' |
| 107 | |
| 108 | test_done |