Sync with 'maint'
[alt-git.git] / t / t6417-merge-ours-theirs.sh
blob482b73a998ff2aa6651fc3fc7bd845fffd2c80c3
1 #!/bin/sh
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
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 test_expect_success setup '
11 test_write_lines 1 2 3 4 5 6 7 8 9 >file &&
12 git add file &&
13 cp file elif &&
14 git commit -m initial &&
16 sed -e "s/1/one/" -e "s/9/nine/" >file <elif &&
17 git commit -a -m ours &&
19 git checkout -b side HEAD^ &&
21 sed -e "s/9/nueve/" >file <elif &&
22 git commit -a -m theirs &&
24 git checkout main^0
27 test_expect_success 'plain recursive - should conflict' '
28 git reset --hard main &&
29 test_must_fail git merge -s recursive side &&
30 grep nine file &&
31 grep nueve file &&
32 ! grep 9 file &&
33 grep one file &&
34 ! grep 1 file
37 test_expect_success 'recursive favouring theirs' '
38 git reset --hard main &&
39 git merge -s recursive -Xtheirs side &&
40 ! grep nine file &&
41 grep nueve file &&
42 ! grep 9 file &&
43 grep one file &&
44 ! grep 1 file
47 test_expect_success 'recursive favouring ours' '
48 git reset --hard main &&
49 git merge -s recursive -X ours side &&
50 grep nine file &&
51 ! grep nueve file &&
52 ! grep 9 file &&
53 grep one file &&
54 ! grep 1 file
57 test_expect_success 'binary file with -Xours/-Xtheirs' '
58 echo file binary >.gitattributes &&
60 git reset --hard main &&
61 git merge -s recursive -X theirs side &&
62 git diff --exit-code side HEAD -- file &&
64 git reset --hard main &&
65 git merge -s recursive -X ours side &&
66 git diff --exit-code main HEAD -- file
69 test_expect_success 'pull passes -X to underlying merge' '
70 git reset --hard main && git pull --no-rebase -s recursive -Xours . side &&
71 git reset --hard main && git pull --no-rebase -s recursive -X ours . side &&
72 git reset --hard main && git pull --no-rebase -s recursive -Xtheirs . side &&
73 git reset --hard main && git pull --no-rebase -s recursive -X theirs . side &&
74 git reset --hard main && test_must_fail git pull --no-rebase -s recursive -X bork . side
77 test_expect_success SYMLINKS 'symlink with -Xours/-Xtheirs' '
78 git reset --hard main &&
79 git checkout -b two main &&
80 ln -s target-zero link &&
81 git add link &&
82 git commit -m "add link pointing to zero" &&
84 ln -f -s target-two link &&
85 git commit -m "add link pointing to two" link &&
87 git checkout -b one HEAD^ &&
88 ln -f -s target-one link &&
89 git commit -m "add link pointing to one" link &&
91 # we expect symbolic links not to resolve automatically, of course
92 git checkout one^0 &&
93 test_must_fail git merge -s recursive two &&
95 # favor theirs to resolve to target-two?
96 git reset --hard &&
97 git checkout one^0 &&
98 git merge -s recursive -X theirs two &&
99 git diff --exit-code two HEAD link &&
101 # favor ours to resolve to target-one?
102 git reset --hard &&
103 git checkout one^0 &&
104 git merge -s recursive -X ours two &&
105 git diff --exit-code one HEAD link
109 test_done