Skip to content

Commit 29dc133

Browse files
committed
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>
1 parent deda26b commit 29dc133

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

git-merge-one-file.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ case "${1:-.}${2:-.}${3:-.}" in
4848
;;
4949
"..$3")
5050
echo "Adding $4"
51-
test -f "$4" || {
51+
if test -f "$4"
52+
then
5253
echo "ERROR: untracked $4 is overwritten by the merge."
5354
exit 1
54-
}
55+
fi
5556
git update-index --add --cacheinfo "$7" "$3" "$4" &&
5657
exec git checkout-index -u -f -- "$4"
5758
;;

t/t1004-read-tree-m-u-wf.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,50 @@ test_expect_success '3-way not overwriting local changes (their side)' '
157157
158158
'
159159

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+
160206
test_done

0 commit comments

Comments
 (0)