tag: Refuse to use HEAD as a tagname
authorSven Strickroth <[email protected]>
Mon, 7 Apr 2025 19:18:20 +0000 (7 21:18 +0200)
committerSven Strickroth <[email protected]>
Mon, 7 Apr 2025 19:18:20 +0000 (7 21:18 +0200)
Sync with vanilla Git, cf. https://github.com/git/git/commit/bbd445d5efd415

Signed-off-by: Sven Strickroth <[email protected]>
src/libgit2/tag.c
tests/libgit2/refs/tags/name.c

index cad9e41..d12efdb 100644 (file)
@@ -263,8 +263,10 @@ static bool tag_name_is_valid(const char *tag_name)
        /*
         * Discourage tag name starting with dash,
         * https://github.com/git/git/commit/4f0accd638b8d2
+        * and refuse to use HEAD as a tagname,
+        * https://github.com/git/git/commit/bbd445d5efd415
         */
-       return tag_name[0] != '-';
+       return tag_name[0] != '-' && git__strcmp(tag_name, "HEAD");
 }
 
 static int git_tag_create__internal(
index 1dd1760..bc6cbae 100644 (file)
@@ -11,7 +11,9 @@ void test_refs_tags_name__is_name_valid(void)
 {
        cl_assert_equal_i(true, name_is_valid("sometag"));
        cl_assert_equal_i(true, name_is_valid("test/sometag"));
+       cl_assert_equal_i(true, name_is_valid("test/HEAD"));
 
        cl_assert_equal_i(false, name_is_valid(""));
        cl_assert_equal_i(false, name_is_valid("-dash"));
+       cl_assert_equal_i(false, name_is_valid("HEAD"));
 }