Skip to content

Commit

Permalink
pull: allow "git pull origin $something:$current_branch" into an unbo…
Browse files Browse the repository at this point in the history
…rn 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>
  • Loading branch information
Junio C Hamano committed Oct 17, 2008
1 parent 8ee5d73 commit b0ad11e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions git-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
git fetch --update-head-ok "$@" || exit 1

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

Expand Down Expand Up @@ -172,7 +172,7 @@ esac

if test -z "$orig_head"
then
git update-ref -m "initial pull" HEAD $merge_head "" &&
git update-ref -m "initial pull" HEAD $merge_head "$curr_head" &&
git read-tree --reset -u HEAD || exit 1
exit
fi
Expand Down
12 changes: 12 additions & 0 deletions t/t5520-pull.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ test_expect_success 'checking the results' '
diff file cloned/file
'

test_expect_success 'pulling into void using master:master' '
mkdir cloned-uho &&
(
cd cloned-uho &&
git init &&
git pull .. master:master
) &&
test -f file &&
test -f cloned-uho/file &&
test_cmp file cloned-uho/file
'

test_expect_success 'test . as a remote' '
git branch copy master &&
Expand Down

0 comments on commit b0ad11e

Please sign in to comment.