Skip to content

Commit 8c8674f

Browse files
peffgitster
authored andcommitted
pull: do not clobber untracked files on initial pull
For a pull into an unborn branch, we do not use "git merge" at all. Instead, we call read-tree directly. However, we used the --reset parameter instead of "-m", which turns off the safety features. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 44ec754 commit 8c8674f

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

git-pull.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ esac
272272
if test -z "$orig_head"
273273
then
274274
git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
275-
git read-tree --reset -u HEAD || exit 1
275+
git read-tree -m -u HEAD || exit 1
276276
exit
277277
fi
278278

t/t5520-pull.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,17 @@ test_expect_success 'pulling into void using master:master' '
4646
test_cmp file cloned-uho/file
4747
'
4848

49+
test_expect_success 'pulling into void does not overwrite untracked files' '
50+
git init cloned-untracked &&
51+
(
52+
cd cloned-untracked &&
53+
echo untracked >file &&
54+
test_must_fail git pull .. master &&
55+
echo untracked >expect &&
56+
test_cmp expect file
57+
)
58+
'
59+
4960
test_expect_success 'test . as a remote' '
5061
5162
git branch copy master &&

0 commit comments

Comments
 (0)