@matheusbsbs / matheus-bagliano / commits / b0ad11ea16
Fork 0

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 <gitster@pobox.com>

Junio C Hamano committed Oct 14, 2008 at 15:32 UTC b0ad11ea165e07308fc02a5091efbe2e2d22237c
2 files changed +14 -2
git-pull.sh
+2 -2
@@ -124,7 +124,7 @@ orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
124 git fetch --update-head-ok "$@" || exit 1
125
126 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"
128 then
129 # The fetch involved updating the current branch.
130
@@ -172,7 +172,7 @@ esac
172
173 if test -z "$orig_head"
174 then
175 - git update-ref -m "initial pull" HEAD $merge_head "" &&
175 + git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
176 git read-tree --reset -u HEAD || exit 1
177 exit
178 fi
t/t5520-pull.sh
+12
@@ -29,6 +29,18 @@ test_expect_success 'checking the results' '
29 diff file cloned/file
30 '
31
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 +
44 test_expect_success 'test . as a remote' '
45
46 git branch copy master &&