]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6417-merge-ours-theirs.sh
midx: disable replace objects
[thirdparty/git.git] / t / t6417-merge-ours-theirs.sh
CommitLineData
8cc5b290
AP
1#!/bin/sh
2
3test_description='Merge-recursive ours and theirs variants'
5902f5f4 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
ece3974b 7TEST_PASSES_SANITIZE_LEAK=true
8cc5b290
AP
8. ./test-lib.sh
9
10test_expect_success setup '
08495412 11 test_write_lines 1 2 3 4 5 6 7 8 9 >file &&
8cc5b290
AP
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
5902f5f4 24 git checkout main^0
8cc5b290
AP
25'
26
27test_expect_success 'plain recursive - should conflict' '
5902f5f4 28 git reset --hard main &&
8cc5b290
AP
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
37test_expect_success 'recursive favouring theirs' '
5902f5f4 38 git reset --hard main &&
8cc5b290
AP
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
47test_expect_success 'recursive favouring ours' '
5902f5f4 48 git reset --hard main &&
8cc5b290
AP
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
a944af1d 57test_expect_success 'binary file with -Xours/-Xtheirs' '
155a4b71 58 echo file binary >.gitattributes &&
a944af1d 59
5902f5f4 60 git reset --hard main &&
a944af1d
JH
61 git merge -s recursive -X theirs side &&
62 git diff --exit-code side HEAD -- file &&
63
5902f5f4 64 git reset --hard main &&
a944af1d 65 git merge -s recursive -X ours side &&
5902f5f4 66 git diff --exit-code main HEAD -- file
a944af1d
JH
67'
68
69test_expect_success 'pull passes -X to underlying merge' '
031e2f7a
EN
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
ee2c7955
AP
75'
76
fd48b464 77test_expect_success SYMLINKS 'symlink with -Xours/-Xtheirs' '
5902f5f4
JS
78 git reset --hard main &&
79 git checkout -b two main &&
fd48b464
JH
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
8cc5b290 109test_done