git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/3] push: factor out the detached HEAD error message

From
Ramkumar Ramachandra <artagnon@gmail.com>
Date
May 21, 2013, 18:23 UTC
Message-ID
<1369160600-22337-2-git-send-email-artagnon@gmail.com>
In-Reply-To
<1369160600-22337-1-git-send-email-artagnon@gmail.com>

With push.default set to upstream or simple, and a detached HEAD, git push prints the following error:

  $ 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>

This error is not unique to upstream or simple: current cannot push with a detached HEAD either. So, factor out the error string in preparation for using it in current.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/builtin/push.c b/builtin/push.c
index 909c34d..ef3aa97 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -113,17 +113,19 @@ static NORETURN int die_push_simple(struct branch *branch, struct remote *remote
 	    remote->name, branch->name, advice_maybe);
 }
 
+static const char message_detached_head_die[] =
+	N_("You are not currently on a branch.\n"
+	   "To push the history leading to the current (detached HEAD)\n"
+	   "state now, use\n"
+	   "\n"
+	   "    git push %s HEAD:<name-of-remote-branch>\n");
+
 static void setup_push_upstream(struct remote *remote, int simple)
 {
 	struct strbuf refspec = STRBUF_INIT;
 	struct branch *branch = branch_get(NULL);
 	if (!branch)
-		die(_("You are not currently on a branch.\n"
-		    "To push the history leading to the current (detached HEAD)\n"
-		    "state now, use\n"
-		    "\n"
-		    "    git push %s HEAD:<name-of-remote-branch>\n"),
-		    remote->name);
+		die(_(message_detached_head_die), remote->name);
 	if (!branch->merge_nr || !branch->merge || !branch->remote_name)
 		die(_("The current branch %s has no upstream branch.\n"
 		    "To push the current branch and set the remote as upstream, use\n"
-- 
1.8.3.rc3.7.gc1ff30b
Previous: Ramkumar RamachandraNext: Ramkumar Ramachandra
Message 2 of 17 in “Fixing volatile HEAD in push.default = current”
  1. 0/3 Fixing volatile HEAD in push.default = currentRamkumar Ramachandra, May 21, 2013
  2. 1/3 push: factor out the detached HEAD error messageRamkumar Ramachandra, May 21, 2013
  3. 2/3 push: fail early with detached HEAD and currentRamkumar Ramachandra, May 21, 2013
  4. 3/3 push: don't push the volatile HEAD with currentRamkumar Ramachandra, May 21, 2013
  5. Junio C HamanoMay 21, 2013
  6. Ramkumar RamachandraMay 21, 2013
  7. Junio C HamanoMay 21, 2013
  8. Junio C HamanoMay 21, 2013
  9. Ramkumar RamachandraMay 21, 2013
  10. Junio C HamanoMay 22, 2013
  11. Ramkumar RamachandraMay 22, 2013
  12. Junio C HamanoMay 22, 2013
  13. Ramkumar RamachandraMay 23, 2013
  14. Andreas KreyMay 23, 2013
  15. Junio C HamanoMay 23, 2013
  16. Andreas KreyMay 23, 2013
  17. Junio C HamanoMay 23, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.