@matheusbsbs / matheus-bagliano / commits / 29dc133198
Fork 0

git-merge-one-file: fix longstanding stupid thinko

When a merge result creates a new file, and when our side already has a file in the path, taking the merge result may clobber the untracked file. However, the logic to detect this situation was totally the wrong way. We should complain when the file exists, not when the file does not exist. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Mar 17, 2008 at 16:47 UTC 29dc13319883f97618de6f03e8ffc5dc810d8786
2 files changed +49 -2
git-merge-one-file.sh
+3 -2
@@ -48,10 +48,11 @@ case "${1:-.}${2:-.}${3:-.}" in
48 ;;
49 "..$3")
50 echo "Adding $4"
51 - test -f "$4" || {
51 + if test -f "$4"
52 + then
53 echo "ERROR: untracked $4 is overwritten by the merge."
54 exit 1
54 - }
55 + fi
56 git update-index --add --cacheinfo "$7" "$3" "$4" &&
57 exec git checkout-index -u -f -- "$4"
58 ;;
t/t1004-read-tree-m-u-wf.sh
+46
@@ -157,4 +157,50 @@ test_expect_success '3-way not overwriting local changes (their side)' '
157
158 '
159
160 +test_expect_success 'D/F setup' '
161 +
162 + git reset --hard &&
163 +
164 + git checkout side-a &&
165 + rm -f subdir/file2 &&
166 + mkdir subdir/file2 &&
167 + echo qfwfq >subdir/file2/another &&
168 + git add subdir/file2/another &&
169 + test_tick &&
170 + git commit -m "side-a changes file2 to directory"
171 +
172 +'
173 +
174 +test_expect_success 'D/F' '
175 +
176 + git checkout side-b &&
177 + git read-tree -m -u branch-point side-b side-a &&
178 + git ls-files -u >actual &&
179 + (
180 + a=$(git rev-parse branch-point:subdir/file2)
181 + b=$(git rev-parse side-a:subdir/file2/another)
182 + echo "100644 $a 1 subdir/file2"
183 + echo "100644 $a 2 subdir/file2"
184 + echo "100644 $b 3 subdir/file2/another"
185 + ) >expect &&
186 + test_cmp actual expect
187 +
188 +'
189 +
190 +test_expect_success 'D/F resolve' '
191 +
192 + git reset --hard &&
193 + git checkout side-b &&
194 + git merge-resolve branch-point -- side-b side-a
195 +
196 +'
197 +
198 +test_expect_success 'D/F recursive' '
199 +
200 + git reset --hard &&
201 + git checkout side-b &&
202 + git merge-recursive branch-point -- side-b side-a
203 +
204 +'
205 +
206 test_done