Skip to content

Commit

Permalink
push: support pushing HEAD to real branch name
Browse files Browse the repository at this point in the history
This teaches "push <remote> HEAD" to resolve HEAD on the local
side to its real branch name, e.g. master, and then act as if
the real branch name was specified. So we have a shorthand for
pushing the current branch. Besides HEAD, no other symbolic ref
is resolved.

Thanks to Daniel Barkalow <barkalow@iabervon.org> for suggesting
this implementation, which is much simpler than the
implementation proposed before.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Steffen Prohaska authored and Junio C Hamano committed Nov 19, 2007
1 parent ea55960 commit 47d996a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions builtin-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ static void set_refspecs(const char **refs, int nr)
strcat(tag, refs[i]);
ref = tag;
}
if (!strcmp("HEAD", ref)) {
unsigned char sha1_dummy[20];
ref = resolve_ref(ref, sha1_dummy, 1, NULL);
if (!ref)
die("HEAD cannot be resolved.");
if (prefixcmp(ref, "refs/heads/"))
die("HEAD cannot be resolved to branch.");
ref = xstrdup(ref + 11);
}
add_refspec(ref);
}
}
Expand Down
17 changes: 17 additions & 0 deletions t/t5516-fetch-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,23 @@ test_expect_success 'push with colon-less refspec (4)' '
'

test_expect_success 'push with HEAD' '
mk_test heads/master &&
git checkout master &&
git push testrepo HEAD &&
check_push_result $the_commit heads/master
'

test_expect_success 'push with HEAD nonexisting at remote' '
mk_test heads/master &&
git checkout -b local master &&
git push testrepo HEAD &&
check_push_result $the_commit heads/local
'

test_expect_success 'push with dry-run' '
mk_test heads/master &&
Expand Down

0 comments on commit 47d996a

Please sign in to comment.