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