git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 2/3] push: fail early with detached HEAD and current
Date: Thu, 30 May 2013 00:51:50 +0530	[thread overview]
Message-ID: <1369855311-23367-3-git-send-email-artagnon@gmail.com> (raw)
In-Reply-To: <1369855311-23367-1-git-send-email-artagnon@gmail.com>

Setting push.default to current adds the refspec "HEAD" for the
transport layer to handle.  If "HEAD" doesn't resolve to a branch (and
since no refspec rhs is specified), the push fails after some time with
a cryptic error message:

  $ git push
  error: unable to push to unqualified destination: HEAD
  The destination refspec neither matches an existing ref on the remote nor
  begins with refs/, and we are unable to guess a prefix based on the source ref.
  error: failed to push some refs to 'git@github.com:artagnon/git'

Fail early with a nicer error message:

  $ git push
  fatal: You are not currently on a branch.
  To push the history leading to the current (detached HEAD)
  state now, use

    git push ram HEAD:<name-of-remote-branch>

Just like in the upstream and simple cases.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/builtin/push.c b/builtin/push.c
index ef3aa97..a79038c 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -175,6 +175,8 @@ static void warn_unspecified_push_default_configuration(void)
 
 static void setup_default_push_refspecs(struct remote *remote)
 {
+	struct branch *branch = branch_get(NULL);
+
 	switch (push_default) {
 	default:
 	case PUSH_DEFAULT_UNSPECIFIED:
@@ -194,6 +196,8 @@ static void setup_default_push_refspecs(struct remote *remote)
 		break;
 
 	case PUSH_DEFAULT_CURRENT:
+		if (!branch)
+			die(_(message_detached_head_die), remote->name);
 		add_refspec("HEAD");
 		break;
 
-- 
1.8.3.12.gbd56588

  parent reply	other threads:[~2013-05-29 19:23 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-29 19:21 [PATCH v2 0/3] Early HEAD resolution in push.default = current Ramkumar Ramachandra
2013-05-29 19:21 ` [PATCH 1/3] push: factor out the detached HEAD error message Ramkumar Ramachandra
2013-05-29 19:21 ` Ramkumar Ramachandra [this message]
2013-05-29 19:34   ` [PATCH 2/3] push: fail early with detached HEAD and current Junio C Hamano
2013-05-29 19:37     ` Ramkumar Ramachandra
2013-05-29 19:59       ` Junio C Hamano
2013-05-29 20:04         ` Ramkumar Ramachandra
2013-05-29 19:21 ` [PATCH 3/3] push: make push.default = current use resolved HEAD Ramkumar Ramachandra
  -- strict thread matches above, loose matches on Subject: below --
2013-05-21 18:23 [PATCH 0/3] Fixing volatile HEAD in push.default = current Ramkumar Ramachandra
2013-05-21 18:23 ` [PATCH 2/3] push: fail early with detached HEAD and current Ramkumar Ramachandra

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=1369855311-23367-3-git-send-email-artagnon@gmail.com \
    --to=artagnon@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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).