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

[PATCH] git-branch: rename nor delete should not work when HEAD is detached.

From
Junio C Hamano <junkio@cox.net>
Date
Mar 8, 2007, 22:10 UTC
Message-ID
<7virdb8jys.fsf_-_@assigned-by-dhcp.cox.net>
In-Reply-To
<7vr6rz8khv.fsf@assigned-by-dhcp.cox.net>

While reviewing the latest round of 'branch --track' changes, I noticed that we do not do anything special when renaming or deleting a detached HEAD. We do not have anything to rename nor delete in this case, so instead of attempting to rename/delete refs/heads/HEAD, we should error out.

---
 * CC'ed are not guilty parties, but people who might know the
   code better than others.
diff --git a/builtin-branch.c b/builtin-branch.c
index 06d8a8c..28d4b71 100644
--- a/builtin-branch.c
+++ b/builtin-branch.c
@@ -483,6 +483,8 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
 		die("Failed to resolve HEAD as a valid ref.");
 	if (!strcmp(head, "HEAD")) {
 		detached = 1;
+		if (rename || delete)
+			die("Cannot rename nor delete a detached HEAD");
 	}
 	else {
 		if (prefixcmp(head, "refs/heads/"))
Previous: Junio C HamanoNext: Junio C Hamano
Message 6 of 7 in “git-branch, git-checkout: autosetup for remote branch tracking”
  1. git-branch, git-checkout: autosetup for remote branch trackingPaolo Bonzini, Mar 8, 2007
  2. Junio C HamanoMar 8, 2007
  3. git-branch, git-checkout: autosetup for remote branch trackingPaolo Bonzini, Mar 8, 2007
  4. Junio C HamanoMar 8, 2007
  5. Junio C HamanoMar 8, 2007
  6. git-branch: rename nor delete should not work when HEAD is detached.Junio C Hamano, Mar 8, 2007
  7. Junio C HamanoMar 10, 2007

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.