Skip to content

Commit 54a6fea

Browse files
committed
refs: disallow dash in root ref syntax
Our is_root_ref_syntax() function allows upper-case letters, underscore ("_") and dash ("-"). Our glossary definition was historically vague on the allowed punctuation, but was tightened to just "upper-case characters or underscores" in 74b50a5 (Documentation/glossary: define root refs as refs, 2024-05-15). I don't think we have ever used a root ref within Git with a dash, and the existing open-coded syntax check in refname_is_safe() allows only underscores. This logic comes from 266b182 (refs: add ref_type function, 2015-07-31), but I couldn't find any comment on the dash in the commit message or the list discussion. It's used mostly for is_root_ref(), which further requires that the name either end in "_HEAD" or be one of a specific set of "irregular" root refs. So I don't think we'd ever see a dash in the real world (you'd need to have "FOO-BAR_HEAD"). And because of the rules in refname_is_safe(), such a ref would not be fully functional (you couldn't delete it!). Let's tighten this up now so that the function is consistent with (and can be used in) other spots. Signed-off-by: Jeff King <peff@peff.net>
1 parent c68e8af commit 54a6fea

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

refs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -904,7 +904,7 @@ static int is_root_ref_syntax(const char *refname)
904904
const char *c;
905905

906906
for (c = refname; *c; c++) {
907-
if (!isupper(*c) && *c != '-' && *c != '_')
907+
if (!isupper(*c) && *c != '_')
908908
return 0;
909909
}
910910

0 commit comments

Comments
 (0)