Skip to content

Commit

Permalink
transport-helper: add support to push symbolic refs
Browse files Browse the repository at this point in the history
For example 'HEAD'.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Felipe Contreras authored and Junio C Hamano committed Apr 21, 2014
1 parent d98c815 commit 9193f74
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions t/t5801-remote-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,14 @@ test_expect_success 'push new branch with old:new refspec' '
compare_refs local HEAD server refs/heads/new-refspec
'

test_expect_success 'push new branch with HEAD:new refspec' '
(cd local &&
git checkout new-name
git push origin HEAD:new-refspec-2
) &&
compare_refs local HEAD server refs/heads/new-refspec-2
'

test_expect_success 'forced push' '
(cd local &&
git checkout -b force-test &&
Expand Down
11 changes: 10 additions & 1 deletion transport-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,16 @@ static int push_refs_with_export(struct transport *transport,
if (ref->peer_ref) {
if (strcmp(ref->name, ref->peer_ref->name)) {
struct strbuf buf = STRBUF_INIT;
strbuf_addf(&buf, "%s:%s", ref->peer_ref->name, ref->name);
const char *name;
int flag;

/* Follow symbolic refs (mainly for HEAD). */
name = resolve_ref_unsafe(ref->peer_ref->name, sha1, 1, &flag);
if (!name || !(flag & REF_ISSYMREF))
name = ref->peer_ref->name;

strbuf_addf(&buf, "%s:%s", name, ref->name);

string_list_append(&revlist_args, "--refspec");
string_list_append(&revlist_args, buf.buf);
strbuf_release(&buf);
Expand Down

0 comments on commit 9193f74

Please sign in to comment.