From 12cfa792b8657cfd37523df83df0a83d987570a5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 1 Sep 2016 15:38:02 -0700 Subject: symbolic-ref -d: do not allow removal of HEAD If you delete the symbolic-ref HEAD from a repository, Git no longer considers the repository valid, and even "git symbolic-ref HEAD refs/heads/master" would not be able to recover from that state (although "git init" can, but that is a sure sign that you are talking about a "broken" repository). In the spirit similar to afe5d3d5 ("symbolic ref: refuse non-ref targets in HEAD", 2009-01-29), forbid removal of HEAD to avoid corrupting a repository. Signed-off-by: Junio C Hamano --- builtin/symbolic-ref.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'builtin/symbolic-ref.c') diff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c index 9c29a64e43..96eed94468 100644 --- a/builtin/symbolic-ref.c +++ b/builtin/symbolic-ref.c @@ -56,6 +56,8 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix) ret = check_symref(argv[0], 1, 0, 0); if (ret) die("Cannot delete %s, not a symbolic ref", argv[0]); + if (!strcmp(argv[0], "HEAD")) + die("deleting '%s' is not allowed", argv[0]); return delete_ref(argv[0], NULL, REF_NODEREF); } -- cgit v1.2.3