t6042: Add a testcase where undetected rename causes silent file deletion
There are cases where history should merge cleanly, and which current git does merge cleanly despite not detecting a rename; however the merge currently nukes files that should not be removed. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Aug 11, 2011 at 23:19 UTC
a0551f212edd13e3df0d3dcd5abf148e0f003e59
1 file changed
+65
t/t6042-merge-rename-corner-cases.sh
+65
@@ -133,4 +133,69 @@ test_expect_failure 'missed conflict if rename not detected' '
133
test_must_fail git merge -s recursive D^0
134
'
135
136
+# Tests for undetected rename/add-source causing a file to erroneously be
137
+# deleted (and for mishandled rename/rename(1to1) causing the same issue).
138
+#
139
+# This test uses a rename/rename(1to1)+add-source conflict (1to1 means the
140
+# same file is renamed on both sides to the same thing; it should trigger
141
+# the 1to2 logic, which it would do if the add-source didn't cause issues
142
+# for git's rename detection):
143
+# Commit A: new file: a
144
+# Commit B: rename a->b
145
+# Commit C: rename a->b, add unrelated a
146
+
147
+test_expect_success 'setup undetected rename/add-source causes data loss' '
148
+ git rm -rf . &&
149
+ git clean -fdqx &&
150
+ rm -rf .git &&
151
+ git init &&
152
+
153
+ printf "1\n2\n3\n4\n5\n" >a &&
154
+ git add a &&
155
+ git commit -m A &&
156
+ git tag A &&
157
+
158
+ git checkout -b B A &&
159
+ git mv a b &&
160
+ git commit -m B &&
161
+
162
+ git checkout -b C A &&
163
+ git mv a b &&
164
+ echo foobar >a &&
165
+ git add a &&
166
+ git commit -m C
167
+'
168
+
169
+test_expect_failure 'detect rename/add-source and preserve all data' '
170
+ git checkout B^0 &&
171
+
172
+ git merge -s recursive C^0 &&
173
+
174
+ test 2 -eq $(git ls-files -s | wc -l) &&
175
+ test 2 -eq $(git ls-files -u | wc -l) &&
176
+ test 0 -eq $(git ls-files -o | wc -l) &&
177
+
178
+ test -f a &&
179
+ test -f b &&
180
+
181
+ test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
182
+ test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
183
+'
184
+
185
+test_expect_failure 'detect rename/add-source and preserve all data, merge other way' '
186
+ git checkout C^0 &&
187
+
188
+ git merge -s recursive B^0 &&
189
+
190
+ test 2 -eq $(git ls-files -s | wc -l) &&
191
+ test 2 -eq $(git ls-files -u | wc -l) &&
192
+ test 0 -eq $(git ls-files -o | wc -l) &&
193
+
194
+ test -f a &&
195
+ test -f b &&
196
+
197
+ test $(git rev-parse HEAD:b) = $(git rev-parse A:a) &&
198
+ test $(git rev-parse HEAD:a) = $(git rev-parse C:a)
199
+'
200
+
201
test_done