Skip to content

Commit b0ad11e

Browse files
committed
pull: allow "git pull origin $something:$current_branch" into an unborn branch
Some misguided documents floating on the Net suggest this sequence: mkdir newdir && cd newdir git init git remote add origin $url git pull origin master:master "git pull" has known about misguided "pull" that lets the underlying fetch update the current branch for a long time. It also has known about "git pull origin master" into a branch yet to be born. These two workarounds however were not aware of the existence of each other and did not work well together. This fixes it. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8ee5d73 commit b0ad11e

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

git-pull.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
124124
git fetch --update-head-ok "$@" || exit 1
125125

126126
curr_head=$(git rev-parse --verify HEAD 2>/dev/null)
127-
if test "$curr_head" != "$orig_head"
127+
if test -n "$orig_head" && test "$curr_head" != "$orig_head"
128128
then
129129
# The fetch involved updating the current branch.
130130

@@ -172,7 +172,7 @@ esac
172172

173173
if test -z "$orig_head"
174174
then
175-
git update-ref -m "initial pull" HEAD $merge_head "" &&
175+
git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
176176
git read-tree --reset -u HEAD || exit 1
177177
exit
178178
fi

t/t5520-pull.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ test_expect_success 'checking the results' '
2929
diff file cloned/file
3030
'
3131

32+
test_expect_success 'pulling into void using master:master' '
33+
mkdir cloned-uho &&
34+
(
35+
cd cloned-uho &&
36+
git init &&
37+
git pull .. master:master
38+
) &&
39+
test -f file &&
40+
test -f cloned-uho/file &&
41+
test_cmp file cloned-uho/file
42+
'
43+
3244
test_expect_success 'test . as a remote' '
3345
3446
git branch copy master &&

0 commit comments

Comments
 (0)