aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--refs.c2
-rwxr-xr-xt/t7004-tag.sh12
2 files changed, 13 insertions, 1 deletions
diff --git a/refs.c b/refs.c
index a24bfe3845..01ef2a3093 100644
--- a/refs.c
+++ b/refs.c
@@ -735,7 +735,7 @@ int check_branch_ref(struct strbuf *sb, const char *name)
int check_tag_ref(struct strbuf *sb, const char *name)
{
- if (name[0] == '-')
+ if (name[0] == '-' || !strcmp(name, "HEAD"))
return -1;
strbuf_reset(sb);
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index b1316e62f4..34d34b0dfb 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -91,6 +91,18 @@ test_expect_success 'creating a tag using default HEAD should succeed' '
test_must_fail git reflog exists refs/tags/mytag
'
+test_expect_success 'HEAD is forbidden as a tagname' '
+ test_when_finished "git update-ref --no-deref -d refs/tags/HEAD || :" &&
+ test_must_fail git tag HEAD &&
+ test_must_fail git tag -a -m "useless" HEAD
+'
+
+test_expect_success '"git tag" can remove a tag named HEAD' '
+ test_when_finished "git update-ref --no-deref -d refs/tags/HEAD || :" &&
+ git update-ref refs/tags/HEAD HEAD &&
+ git tag -d HEAD
+'
+
test_expect_success 'creating a tag with --create-reflog should create reflog' '
git log -1 \
--format="format:tag: tagging %h (%s, %cd)%n" \