]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6417-merge-ours-theirs.sh
The third batch
[thirdparty/git.git] / t / t6417-merge-ours-theirs.sh
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_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
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 &&
15
16 sed -e "s/1/one/" -e "s/9/nine/" >file <elif &&
17 git commit -a -m ours &&
18
19 git checkout -b side HEAD^ &&
20
21 sed -e "s/9/nueve/" >file <elif &&
22 git commit -a -m theirs &&
23
24 git checkout main^0
25 '
26
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
35 '
36
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
45 '
46
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
55 '
56
57 test_expect_success 'binary file with -Xours/-Xtheirs' '
58 echo file binary >.gitattributes &&
59
60 git reset --hard main &&
61 git merge -s recursive -X theirs side &&
62 git diff --exit-code side HEAD -- file &&
63
64 git reset --hard main &&
65 git merge -s recursive -X ours side &&
66 git diff --exit-code main HEAD -- file
67 '
68
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
75 '
76
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" &&
83
84 ln -f -s target-two link &&
85 git commit -m "add link pointing to two" link &&
86
87 git checkout -b one HEAD^ &&
88 ln -f -s target-one link &&
89 git commit -m "add link pointing to one" link &&
90
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 &&
94
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 &&
100
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
106
107 '
108
109 test_done