This teaches "push <remote> HEAD" to resolve HEAD on the local side to its real ref name, e.g. refs/heads/master, and then use the real ref name on the remote side to search a matching remote ref. Signed-off-by: Steffen Prohaska <prohaska@xxxxxx> --- remote.c | 13 ++++++++++--- t/t5516-fetch-push.sh | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/remote.c b/remote.c index f26f0e0..58bc019 100644 --- a/remote.c +++ b/remote.c @@ -439,6 +439,8 @@ static struct ref *try_explicit_object_name(const char *name) unsigned char sha1[20]; struct ref *ref; int len; + char *real_name = 0; + const char *best_name; if (!*name) { ref = alloc_ref(20); @@ -446,12 +448,17 @@ static struct ref *try_explicit_object_name(const char *name) hashclr(ref->new_sha1); return ref; } - if (get_sha1(name, sha1)) + if (get_sha1_with_real_ref(name, sha1, &real_name)) return NULL; - len = strlen(name) + 1; + best_name = real_name ? real_name : name; + len = strlen(best_name) + 1; ref = alloc_ref(len); - memcpy(ref->name, name, len); + memcpy(ref->name, best_name, len); hashcpy(ref->new_sha1, sha1); + + if (real_name) { + free(real_name); + } return ref; } diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 8629cf2..97a032e 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -274,4 +274,26 @@ test_expect_success 'push with colon-less refspec (4)' ' ' +test_expect_success 'push with HEAD' ' + + mk_test heads/master && + git push testrepo HEAD && + check_push_result $the_commit heads/master + +' + +test_expect_success 'push with HEAD not existing at remote' ' + + mk_test heads/master && + git checkout -b local master && + if git push testrepo HEAD + then + echo "Oops, should have failed" + false + else + check_push_result $the_first_commit heads/master + fi + +' + test_done -- 1.5.3.4.224.gc6b84 - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html