3 test_description
='recursive merge corner cases'
17 test_expect_success
'setup basic criss-cross + rename with no modifications' '
18 ten="0 1 2 3 4 5 6 7 8 9"
21 echo line $i in a sample file
25 echo line $i in another sample file
28 test_tick && git commit -m initial &&
33 test_tick && git commit -m R1 &&
37 test_tick && git commit -m L1 &&
40 test_tick && git merge -s ours R1 &&
44 test_tick && git merge -s ours L1 &&
48 test_expect_success
'merge simple rename+criss-cross with no modifications' '
52 test_must_fail git merge -s recursive R2^0 &&
54 test 5 = $(git ls-files -s | wc -l) &&
55 test 3 = $(git ls-files -u | wc -l) &&
56 test 0 = $(git ls-files -o | wc -l) &&
58 test $(git rev-parse :0:one) = $(git rev-parse L2:one) &&
59 test $(git rev-parse :0:two) = $(git rev-parse R2:two) &&
60 test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
61 test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
65 test_must_fail git merge-file \
66 -L "Temporary merge branch 2" \
68 -L "Temporary merge branch 1" \
70 test $(git rev-parse :1:three) = $(git hash-object merged)
74 # Same as before, but modify L1 slightly:
85 test_expect_success
'setup criss-cross + rename merges with basic modification' '
91 ten="0 1 2 3 4 5 6 7 8 9"
94 echo line $i in a sample file
98 echo line $i in another sample file
101 test_tick && git commit -m initial &&
104 git checkout -b R1 &&
108 test_tick && git commit -m R1 &&
112 test_tick && git commit -m L1 &&
115 test_tick && git merge -s ours R1 &&
119 test_tick && git merge -s ours L1 &&
123 test_expect_failure
'merge criss-cross + rename merges with basic modification' '
127 test_must_fail git merge -s recursive R2^0 &&
129 test 5 = $(git ls-files -s | wc -l) &&
130 test 3 = $(git ls-files -u | wc -l) &&
131 test 0 = $(git ls-files -o | wc -l) &&
133 test $(git rev-parse :0:one) = $(git rev-parse L2:one) &&
134 test $(git rev-parse :0:two) = $(git rev-parse R2:two) &&
135 test $(git rev-parse :2:three) = $(git rev-parse L2:three) &&
136 test $(git rev-parse :3:three) = $(git rev-parse R2:three) &&
138 head -n 10 two >merged &&
141 test_must_fail git merge-file \
142 -L "Temporary merge branch 2" \
144 -L "Temporary merge branch 1" \
145 merged empty merge-me &&
146 test $(git rev-parse :1:three) = $(git hash-object merged)
150 # For the next test, we start with three commits in two lines of development
151 # which setup a rename/add conflict:
152 # Commit A: File 'a' exists
153 # Commit B: Rename 'a' -> 'new_a'
154 # Commit C: Modify 'a', create different 'new_a'
155 # Later, two different people merge and resolve differently:
156 # Commit D: Merge B & C, ignoring separately created 'new_a'
157 # Commit E: Merge B & C making use of some piece of secondary 'new_a'
158 # Finally, someone goes to merge D & E. Does git detect the conflict?
169 test_expect_success
'setup differently handled merges of rename/add conflict' '
175 printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" >a &&
177 test_tick && git commit -m A &&
182 echo "other content" >>new_a &&
184 test_tick && git commit -m C &&
188 test_tick && git commit -m B &&
191 test_must_fail git merge C &&
193 test_tick && git commit -m D &&
197 test_must_fail git merge B &&
198 rm new_a~HEAD new_a &&
199 printf "Incorrectly merged content" >>new_a &&
201 test_tick && git commit -m E &&
205 test_expect_failure
'git detects differently handled merges conflict' '
209 git merge -s recursive E^0 && {
210 echo "BAD: should have conflicted"
211 test "Incorrectly merged content" = "$(cat new_a)" &&
212 echo "BAD: Silently accepted wrong content"
216 test 3 = $(git ls-files -s | wc -l) &&
217 test 3 = $(git ls-files -u | wc -l) &&
218 test 0 = $(git ls-files -o | wc -l) &&
220 test $(git rev-parse :2:new_a) = $(git rev-parse D:new_a) &&
221 test $(git rev-parse :3:new_a) = $(git rev-parse E:new_a) &&
223 git cat-file -p B:new_a >>merged &&
224 git cat-file -p C:new_a >>merge-me &&
226 test_must_fail git merge-file \
227 -L "Temporary merge branch 2" \
229 -L "Temporary merge branch 1" \
230 merged empty merge-me &&
231 test $(git rev-parse :1:new_a) = $(git hash-object merged)