aboutsummaryrefslogtreecommitdiff
path: root/t/t1401-symbolic-ref.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2016-09-01 15:38:02 -0700
committerJunio C Hamano <gitster@pobox.com>2016-09-02 09:01:38 -0700
commit12cfa792b8657cfd37523df83df0a83d987570a5 (patch)
tree8d79e6b3a0f2b1a4bf1e7b773a39d14751ff92c9 /t/t1401-symbolic-ref.sh
parente0c1ceafc5bece92d35773a75fff59497e1d9bd5 (diff)
downloadgit-12cfa792b8657cfd37523df83df0a83d987570a5.tar.gz
git-12cfa792b8657cfd37523df83df0a83d987570a5.tar.xz
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 <gitster@pobox.com>
Diffstat (limited to 't/t1401-symbolic-ref.sh')
-rwxr-xr-xt/t1401-symbolic-ref.sh21
1 files changed, 14 insertions, 7 deletions
diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
index ca3fa406c..eec3e90f9 100755
--- a/t/t1401-symbolic-ref.sh
+++ b/t/t1401-symbolic-ref.sh
@@ -33,18 +33,25 @@ test_expect_success 'symbolic-ref refuses bare sha1' '
'
reset_to_sane
-test_expect_success 'symbolic-ref deletes HEAD' '
- git symbolic-ref -d HEAD &&
+test_expect_success 'HEAD cannot be removed' '
+ test_must_fail git symbolic-ref -d HEAD
+'
+
+reset_to_sane
+
+test_expect_success 'symbolic-ref can be deleted' '
+ git symbolic-ref NOTHEAD refs/heads/foo &&
+ git symbolic-ref -d NOTHEAD &&
test_path_is_file .git/refs/heads/foo &&
- test_path_is_missing .git/HEAD
+ test_path_is_missing .git/NOTHEAD
'
reset_to_sane
-test_expect_success 'symbolic-ref deletes dangling HEAD' '
- git symbolic-ref HEAD refs/heads/missing &&
- git symbolic-ref -d HEAD &&
+test_expect_success 'symbolic-ref can delete dangling symref' '
+ git symbolic-ref NOTHEAD refs/heads/missing &&
+ git symbolic-ref -d NOTHEAD &&
test_path_is_missing .git/refs/heads/missing &&
- test_path_is_missing .git/HEAD
+ test_path_is_missing .git/NOTHEAD
'
reset_to_sane