Skip to content

Commit 4b3ffe5

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 97b1b4f commit 4b3ffe5

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
@@ -274,7 +274,7 @@ esac
274274
if test -z "$orig_head"
275275
then
276276
git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
277-
git read-tree --reset -u HEAD || exit 1
277+
git read-tree -m -u HEAD || exit 1
278278
exit
279279
fi
280280

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)