Thread (1 message) 1 message, 1 author, 2016-06-15
DORMANTno replies

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

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:42:58
Subsystem: the rest · Maintainer: Linus Torvalds

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/"))
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help