[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/"))