Skip to content

Commit

Permalink
pull: do not clobber untracked files on initial pull
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Mar 25, 2011
1 parent 97b1b4f commit 4b3ffe5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ esac
if test -z "$orig_head"
then
git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
git read-tree --reset -u HEAD || exit 1
git read-tree -m -u HEAD || exit 1
exit
fi

Expand Down
11 changes: 11 additions & 0 deletions t/t5520-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,17 @@ test_expect_success 'pulling into void using master:master' '
test_cmp file cloned-uho/file
'

test_expect_success 'pulling into void does not overwrite untracked files' '
git init cloned-untracked &&
(
cd cloned-untracked &&
echo untracked >file &&
test_must_fail git pull .. master &&
echo untracked >expect &&
test_cmp expect file
)
'

test_expect_success 'test . as a remote' '
git branch copy master &&
Expand Down

0 comments on commit 4b3ffe5

Please sign in to comment.