@matheusbsbs / matheus-bagliano / commits / f63622c0a9
Fork 0

t6036: Add testcase for undetected conflict

If merging two lines of development involves a rename/add conflict, and two different people make such a merge but resolve it differently, and then someone tries to merge the resulting two merges, then they should clearly get a conflict due to the different resolutions from the previous developers. However, in some such cases the conflict would not be detected and git would silently accept one of the two versions being merged as the final merge resolution. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Sep 20, 2010 at 02:28 UTC f63622c0a9665913f7ebade27910d8094ab4f9c4
1 file changed +85
t/t6036-recursive-corner-cases.sh
+85
@@ -146,4 +146,89 @@ test_expect_failure 'merge criss-cross + rename merges with basic modification'
146 test $(git rev-parse :1:three) = $(git hash-object merged)
147 '
148
149 +#
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?
159 +#
160 +# B D
161 +# o---o
162 +# / \ / \
163 +# A o X ? F
164 +# \ / \ /
165 +# o---o
166 +# C E
167 +#
168 +
169 +test_expect_success 'setup differently handled merges of rename/add conflict' '
170 + git rm -rf . &&
171 + git clean -fdqx &&
172 + rm -rf .git &&
173 + git init &&
174 +
175 + printf "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n" >a &&
176 + git add a &&
177 + test_tick && git commit -m A &&
178 +
179 + git branch B &&
180 + git checkout -b C &&
181 + echo 10 >>a &&
182 + echo "other content" >>new_a &&
183 + git add a new_a &&
184 + test_tick && git commit -m C &&
185 +
186 + git checkout B &&
187 + git mv a new_a &&
188 + test_tick && git commit -m B &&
189 +
190 + git checkout B^0 &&
191 + test_must_fail git merge C &&
192 + git clean -f &&
193 + test_tick && git commit -m D &&
194 + git tag D &&
195 +
196 + git checkout C^0 &&
197 + test_must_fail git merge B &&
198 + rm new_a~HEAD new_a &&
199 + printf "Incorrectly merged content" >>new_a &&
200 + git add -u &&
201 + test_tick && git commit -m E &&
202 + git tag E
203 +'
204 +
205 +test_expect_failure 'git detects differently handled merges conflict' '
206 + git reset --hard &&
207 + git checkout D^0 &&
208 +
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"
213 + return 1
214 + }
215 +
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) &&
219 +
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) &&
222 +
223 + git cat-file -p B:new_a >>merged &&
224 + git cat-file -p C:new_a >>merge-me &&
225 + >empty &&
226 + test_must_fail git merge-file \
227 + -L "Temporary merge branch 2" \
228 + -L "" \
229 + -L "Temporary merge branch 1" \
230 + merged empty merge-me &&
231 + test $(git rev-parse :1:new_a) = $(git hash-object merged)
232 +'
233 +
234 test_done