Skip to content

Commit 84dd63e

Browse files
committed
Merge branch 'jk/pull-into-empty'
* jk/pull-into-empty: pull: do not clobber untracked files on initial pull merge: merge unborn index before setting ref
2 parents 82d861f + 4b3ffe5 commit 84dd63e

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,9 +1063,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
10631063
remote_head = peel_to_type(argv[0], 0, NULL, OBJ_COMMIT);
10641064
if (!remote_head)
10651065
die("%s - not something we can merge", argv[0]);
1066+
read_empty(remote_head->sha1, 0);
10661067
update_ref("initial pull", "HEAD", remote_head->sha1, NULL, 0,
10671068
DIE_ON_ERR);
1068-
read_empty(remote_head->sha1, 0);
10691069
return 0;
10701070
} else {
10711071
struct strbuf merge_names = STRBUF_INIT;

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 &&

t/t7607-merge-overwrite.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ test_expect_success 'will not overwrite untracked file on unborn branch' '
157157
test_cmp important c0.c
158158
'
159159

160+
test_expect_success 'failed merge leaves unborn branch in the womb' '
161+
test_must_fail git rev-parse --verify HEAD
162+
'
163+
160164
test_expect_success 'set up unborn branch and content' '
161165
git symbolic-ref HEAD refs/heads/unborn &&
162166
rm -f .git/index &&

0 commit comments

Comments
 (0)