File tree Expand file tree Collapse file tree 2 files changed +38
-2
lines changed
Expand file tree Collapse file tree 2 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -266,10 +266,17 @@ case "$merge_head" in
266266 ;;
267267esac
268268
269+ # Pulling into unborn branch: a shorthand for branching off
270+ # FETCH_HEAD, for lazy typers.
269271if test -z " $orig_head "
270272then
271- git update-ref -m " initial pull" HEAD $merge_head " $curr_head " &&
272- git read-tree -m -u HEAD || exit 1
273+ # Two-way merge: we claim the index is based on an empty tree,
274+ # and try to fast-forward to HEAD. This ensures we will not
275+ # lose index/worktree changes that the user already made on
276+ # the unborn branch.
277+ empty_tree=4b825dc642cb6eb9a060e54bf8d69288fbee4904
278+ git read-tree -m -u $empty_tree $merge_head &&
279+ git update-ref -m " initial pull" HEAD $merge_head " $curr_head "
273280 exit
274281fi
275282
Original file line number Diff line number Diff line change @@ -57,6 +57,35 @@ test_expect_success 'pulling into void does not overwrite untracked files' '
5757 )
5858'
5959
60+ test_expect_success ' pulling into void does not overwrite staged files' '
61+ git init cloned-staged-colliding &&
62+ (
63+ cd cloned-staged-colliding &&
64+ echo "alternate content" >file &&
65+ git add file &&
66+ test_must_fail git pull .. master &&
67+ echo "alternate content" >expect &&
68+ test_cmp expect file &&
69+ git cat-file blob :file >file.index &&
70+ test_cmp expect file.index
71+ )
72+ '
73+
74+
75+ test_expect_success ' pulling into void does not remove new staged files' '
76+ git init cloned-staged-new &&
77+ (
78+ cd cloned-staged-new &&
79+ echo "new tracked file" >newfile &&
80+ git add newfile &&
81+ git pull .. master &&
82+ echo "new tracked file" >expect &&
83+ test_cmp expect newfile &&
84+ git cat-file blob :newfile >newfile.index &&
85+ test_cmp expect newfile.index
86+ )
87+ '
88+
6089test_expect_success ' test . as a remote' '
6190
6291 git branch copy master &&
You can’t perform that action at this time.
0 commit comments