git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steffen Prohaska <prohaska@zib.de>
To: git@vger.kernel.org, ericsson Andreas <ae@op5.se>
Cc: Steffen Prohaska <prohaska@zib.de>
Subject: [REPLACEMENT PATCH 3/6] push: support pushing HEAD to real branch name
Date: Sun, 11 Nov 2007 15:35:07 +0100	[thread overview]
Message-ID: <1194791707467-git-send-email-prohaska@zib.de> (raw)
In-Reply-To: <47370EDF.3090907@op5.se>

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>
---
 builtin-push.c        |    9 +++++++++
 t/t5516-fetch-push.sh |   17 +++++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

prefixcmp() is simpler.

    Steffen

diff --git a/builtin-push.c b/builtin-push.c
index 6d1da07..54fba0e 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -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);
 	}
 }
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 86f9b53..b0ff488 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -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 &&
-- 
1.5.3.5.643.g20245

  reply	other threads:[~2007-11-11 14:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-11 14:01 [REPLACEMENT PATCH 0/6] improve refspec handling in push, refactor matching in fetch Steffen Prohaska
2007-11-11 14:01 ` [PATCH 1/6] push: mention --verbose option in documentation Steffen Prohaska
2007-11-11 14:01   ` [PATCH 2/6] push: teach push to pass --verbose option to transport layer Steffen Prohaska
2007-11-11 14:01     ` [PATCH 3/6] push: support pushing HEAD to real branch name Steffen Prohaska
2007-11-11 14:01       ` [PATCH 4/6] add ref_abbrev_matches_full_with_rules() Steffen Prohaska
2007-11-11 14:01         ` [PATCH 5/6] push: use same rules as git-rev-parse to resolve refspecs Steffen Prohaska
2007-11-11 14:01           ` [PATCH 6/6] refactor fetch's ref matching to use ref_abbrev_matches_full_with_rules() Steffen Prohaska
2007-11-11 14:55             ` Jakub Narebski
2007-11-11 17:31               ` Steffen Prohaska
2007-11-12 19:51           ` [PATCH 5/6] push: use same rules as git-rev-parse to resolve refspecs Junio C Hamano
2007-11-12 20:48             ` Steffen Prohaska
2007-11-12 19:51         ` [PATCH 4/6] add ref_abbrev_matches_full_with_rules() Junio C Hamano
2007-11-12 20:51           ` Steffen Prohaska
2007-11-11 14:17       ` [PATCH 3/6] push: support pushing HEAD to real branch name Andreas Ericsson
2007-11-11 14:35         ` Steffen Prohaska [this message]
2007-11-11 14:10   ` [PATCH 1/6] push: mention --verbose option in documentation Steffen Prohaska
2007-11-11 14:14     ` Steffen Prohaska
2007-11-11 19:39       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1194791707467-git-send-email-prohaska@zib.de \
    --to=prohaska@zib.de \
    --cc=ae@op5.se \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).