git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] t1402: test forbidden characters in refnames

From
Nikolaus Schuetz via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 20, 2026, 22:20 UTC
Message-ID
<pull.2203.v2.git.1787264417682.gitgitgadget@gmail.com>
In-Reply-To
<pull.2203.git.1786653837190.gitgitgadget@gmail.com>
From: Nikolaus Schuetz <nikolauspschuetz@gmail.com>

git-check-ref-format(1) documents that a refname cannot contain a space, tilde, caret, colon, question-mark, asterisk, open-bracket or backslash, nor the sequence "..", and cannot be the single character "@". Of these, only "?", "\" and ".." were tested embedded in an otherwise-valid refname; "*" was checked only as a lone character or with --refspec-pattern.

Test all of them in that embedded form with a single loop, and check that "@" alone is rejected even with --allow-onelevel -- where "@" is otherwise a valid refname component, as "refs/@" confirms.

Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
---
    t1402: test forbidden characters in refnames
    
    git-check-ref-format(1) documents the characters that a refname may not
    contain (space, tilde, caret, colon, question-mark, asterisk,
    open-bracket) and the rule that it may not be the single character "@".
    t1402 only exercised a few of these directly.
    
    This adds the remaining forbidden characters in embedded form, and
    checks that "@" alone is rejected even with --allow-onelevel, where "@"
    is otherwise a valid refname component (as "refs/@" confirms).
    
    Test-only; documents existing behaviour, in the spirit of 919eb8ace
    (t1402: check for refs ending with a dot).
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-2203%2Fnikolauspschuetz%2Fns%2Ft1402-forbidden-characters-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2203/nikolauspschuetz/ns/t1402-forbidden-characters-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2203
Range-diff vs v1:
 1:  f254db5b09 ! 1:  cc013499f9 t1402: test forbidden characters in refnames
     @@ Commit message
          t1402: test forbidden characters in refnames
      
          git-check-ref-format(1) documents that a refname cannot contain a
     -    space, tilde, caret, colon, question-mark, asterisk or open-bracket,
     -    and that it cannot be the single character "@".  Of these, only "?"
     -    was tested as a character embedded in an otherwise-valid refname;
     -    "*" was checked only as a lone character or with --refspec-pattern.
     +    space, tilde, caret, colon, question-mark, asterisk, open-bracket or
     +    backslash, nor the sequence "..", and cannot be the single character
     +    "@".  Of these, only "?", "\" and ".." were tested embedded in an
     +    otherwise-valid refname; "*" was checked only as a lone character or
     +    with --refspec-pattern.
      
     -    Add the remaining forbidden characters in that embedded form, and
     -    check that "@" alone is rejected even with --allow-onelevel -- where
     -    "@" is otherwise a valid refname component, as "refs/@" confirms.
     +    Test all of them in that embedded form with a single loop, and check
     +    that "@" alone is rejected even with --allow-onelevel -- where "@" is
     +    otherwise a valid refname component, as "refs/@" confirms.
      
          Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
      
       ## t/t1402-check-ref-format.sh ##
     -@@ t/t1402-check-ref-format.sh: invalid_ref '.refs/foo'
     +@@ t/t1402-check-ref-format.sh: invalid_ref 'foo/./bar'
     + invalid_ref 'foo/bar/.'
     + invalid_ref '.refs/foo'
       invalid_ref 'refs/heads/foo.'
     - invalid_ref 'heads/foo..bar'
     - invalid_ref 'heads/foo?bar'
     -+invalid_ref 'heads/foo~bar'
     -+invalid_ref 'heads/foo^bar'
     -+invalid_ref 'heads/foo:bar'
     -+invalid_ref 'heads/foo*bar'
     -+invalid_ref 'heads/foo[bar'
     -+invalid_ref 'heads/foo bar'
     +-invalid_ref 'heads/foo..bar'
     +-invalid_ref 'heads/foo?bar'
     ++for c in '?' '~' '^' ':' '*' '[' ' ' '\' '..'
     ++do
     ++	invalid_ref "heads/foo${c}bar"
     ++done
       valid_ref 'foo./bar'
       invalid_ref 'heads/foo.lock'
       invalid_ref 'heads///foo.lock'
     @@ t/t1402-check-ref-format.sh: invalid_ref '.refs/foo'
      +valid_ref 'refs/@'
      +invalid_ref '@' --allow-onelevel
       invalid_ref 'heads/v@{ation'
     - invalid_ref 'heads/foo\bar'
     +-invalid_ref 'heads/foo\bar'
       invalid_ref "$(printf 'heads/foo\t')"
     + invalid_ref "$(printf 'heads/foo\177')"
     + valid_ref "$(printf 'heads/fu\303\237')"
 t/t1402-check-ref-format.sh | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh
index cabc516ae9..9dd64662b2 100755
--- a/t/t1402-check-ref-format.sh
+++ b/t/t1402-check-ref-format.sh
@@ -49,16 +49,19 @@ invalid_ref 'foo/./bar'
 invalid_ref 'foo/bar/.'
 invalid_ref '.refs/foo'
 invalid_ref 'refs/heads/foo.'
-invalid_ref 'heads/foo..bar'
-invalid_ref 'heads/foo?bar'
+for c in '?' '~' '^' ':' '*' '[' ' ' '\' '..'
+do
+	invalid_ref "heads/foo${c}bar"
+done
 valid_ref 'foo./bar'
 invalid_ref 'heads/foo.lock'
 invalid_ref 'heads///foo.lock'
 invalid_ref 'foo.lock/bar'
 invalid_ref 'foo.lock///bar'
 valid_ref 'heads/foo@bar'
+valid_ref 'refs/@'
+invalid_ref '@' --allow-onelevel
 invalid_ref 'heads/v@{ation'
-invalid_ref 'heads/foo\bar'
 invalid_ref "$(printf 'heads/foo\t')"
 invalid_ref "$(printf 'heads/foo\177')"
 valid_ref "$(printf 'heads/fu\303\237')"

base-commit: 745601a9a94110d74769ab605ccd4f61339758d2
-- 
gitgitgadget
Previous: Nikolaus SchuetzNext: Junio C Hamano
Message 5 of 7 in “t1402: test forbidden characters in refnames”
  1. t1402: test forbidden characters in refnamesNikolaus Schuetz via GitGitGadget, Aug 13, 2026
  2. Patrick SteinhardtAug 19, 2026
  3. Junio C HamanoAug 19, 2026
  4. Nikolaus SchuetzAug 20, 2026
  5. t1402: test forbidden characters in refnamesNikolaus Schuetz via GitGitGadget, Aug 20, 2026
  6. Junio C HamanoAug 21, 2026
  7. Nikolaus SchuetzAug 23, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.