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

[PATCH 3/3] push: don't push the volatile HEAD with current

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

Since a push does not lock the "HEAD" ref, there is no guarantee that it will remain the same for the entire operation of the push. Practically, this means that with push.default set to current:

  # on branch push-current-head
  $ git push
  # on another terminal
  $ git checkout master
  # return to the first terminal
  # the push tried to push master!

Avoid this confusion by adding the branch that HEAD resolves to as the refspec to push (as opposed to the literal "HEAD"). With this change, the output of the push changes subtly from:

  $ git push
  ...
   * [new branch]      HEAD -> push-current-head
to:
  $ git push
  ...
   * [new branch]      push-current-head -> push-current-head
Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/push.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/push.c b/builtin/push.c
index a79038c..d819487 100644
--- a/builtin/push.c
+++ b/builtin/push.c
@@ -198,7 +198,7 @@ static void setup_default_push_refspecs(struct remote *remote)
 	case PUSH_DEFAULT_CURRENT:
 		if (!branch)
 			die(_(message_detached_head_die), remote->name);
-		add_refspec("HEAD");
+		add_refspec(branch->name);
 		break;
 
 	case PUSH_DEFAULT_NOTHING:
-- 
1.8.3.rc3.7.gc1ff30b
Previous: Ramkumar RamachandraNext: Junio C Hamano
Message 4 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.