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
266
266
;;
267
267
esac
268
268
269
+ # Pulling into unborn branch: a shorthand for branching off
270
+ # FETCH_HEAD, for lazy typers.
269
271
if test -z " $orig_head "
270
272
then
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 "
273
280
exit
274
281
fi
275
282
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' '
57
57
)
58
58
'
59
59
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
+
60
89
test_expect_success ' test . as a remote' '
61
90
62
91
git branch copy master &&
You can’t perform that action at this time.
0 commit comments