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

[PATCH v3] t1401: check symbolic-ref failure and --quiet silence on a non-symbolic ref

From
Nikolaus Schuetz via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 26, 2026, 16:51 UTC
Message-ID
<pull.2204.v3.git.1787763107646.gitgitgadget@gmail.com>
In-Reply-To
<pull.2204.git.1786655554197.gitgitgadget@gmail.com>
From: Nikolaus Schuetz <nikolauspschuetz@gmail.com>

git-symbolic-ref(1) documents that reading a name that is not a symbolic ref fails, and that --quiet does so silently. Tests such as t2020 and t5621 already rely on "symbolic-ref -q HEAD" failing on a detached HEAD, but none checks that the plain form reports the error or that --quiet stays silent.

Assert that a non-symbolic ref fails with the "is not a symbolic ref" message, and that --quiet fails with no output. Use test_must_fail rather than pinning the exact exit codes, which are documented but not worth freezing in the test.

Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
---
    t1401: test symbolic-ref exit codes on a non-symbolic ref
    
    git-symbolic-ref(1) documents that reading a name that is not a symbolic
    ref exits with a non-zero status, and that --quiet does so silently
    rather than printing a diagnostic. This exit-code contract was untested.
    
    This adds two tests: querying a non-symbolic ref exits 128 with the
    usual "is not a symbolic ref" message, and --quiet instead exits 1 with
    no output.
    
    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-2204%2Fnikolauspschuetz%2Fns%2Ft1401-symbolic-ref-quiet-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2204/nikolauspschuetz/ns/t1401-symbolic-ref-quiet-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/2204
Range-diff vs v2:
 1:  22694da869 ! 1:  0391dcceef t1401: check symbolic-ref exit codes and --quiet silence
     @@ Metadata
      Author: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
      
       ## Commit message ##
     -    t1401: check symbolic-ref exit codes and --quiet silence
     +    t1401: check symbolic-ref failure and --quiet silence on a non-symbolic ref
      
          git-symbolic-ref(1) documents that reading a name that is not a
     -    symbolic ref exits non-zero, and that --quiet does so silently.
     -    Tests such as t2020 and t5621 already rely on "symbolic-ref -q HEAD"
     -    failing on a detached HEAD, but none pins the exact exit codes or
     -    checks that --quiet actually suppresses the diagnostic.
     +    symbolic ref fails, and that --quiet does so silently.  Tests such as
     +    t2020 and t5621 already rely on "symbolic-ref -q HEAD" failing on a
     +    detached HEAD, but none checks that the plain form reports the error
     +    or that --quiet stays silent.
      
     -    Assert that a non-symbolic ref exits 128 with the "is not a symbolic
     -    ref" message, and that --quiet instead exits 1 with no output.
     +    Assert that a non-symbolic ref fails with the "is not a symbolic ref"
     +    message, and that --quiet fails with no output.  Use test_must_fail
     +    rather than pinning the exact exit codes, which are documented but not
     +    worth freezing in the test.
      
          Signed-off-by: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
      
     @@ t/t1401-symbolic-ref.sh: test_expect_success 'symbolic-ref refuses bare sha1' '
       
       reset_to_sane
       
     -+test_expect_success 'symbolic-ref reports a non-symbolic ref with exit code 128' '
     -+	test_expect_code 128 git symbolic-ref refs/heads/foo >out 2>err &&
     ++test_expect_success 'symbolic-ref reports a non-symbolic ref' '
     ++	test_must_fail git symbolic-ref refs/heads/foo >out 2>err &&
      +	test_must_be_empty out &&
      +	test_grep "is not a symbolic ref" err
      +'
      +
     -+test_expect_success 'symbolic-ref -q is silent and exits 1 on a non-symbolic ref' '
     -+	test_expect_code 1 git symbolic-ref -q refs/heads/foo >out 2>err &&
     ++test_expect_success 'symbolic-ref -q is silent on a non-symbolic ref' '
     ++	test_must_fail git symbolic-ref -q refs/heads/foo >out 2>err &&
      +	test_must_be_empty out &&
      +	test_must_be_empty err
      +'
 t/t1401-symbolic-ref.sh | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh
index a2a7e94716..fd3aa89a91 100755
--- a/t/t1401-symbolic-ref.sh
+++ b/t/t1401-symbolic-ref.sh
@@ -38,6 +38,18 @@ test_expect_success 'symbolic-ref refuses bare sha1' '
 
 reset_to_sane
 
+test_expect_success 'symbolic-ref reports a non-symbolic ref' '
+	test_must_fail git symbolic-ref refs/heads/foo >out 2>err &&
+	test_must_be_empty out &&
+	test_grep "is not a symbolic ref" err
+'
+
+test_expect_success 'symbolic-ref -q is silent on a non-symbolic ref' '
+	test_must_fail git symbolic-ref -q refs/heads/foo >out 2>err &&
+	test_must_be_empty out &&
+	test_must_be_empty err
+'
+
 test_expect_success 'HEAD cannot be removed' '
 	test_must_fail git symbolic-ref -d HEAD
 '

base-commit: 745601a9a94110d74769ab605ccd4f61339758d2
-- 
gitgitgadget
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 10 of 11 in “t1401: test symbolic-ref exit codes on a non-symbolic ref”
  1. t1401: test symbolic-ref exit codes on a non-symbolic refNikolaus Schuetz via GitGitGadget, Aug 13, 2026
  2. Patrick SteinhardtAug 19, 2026
  3. Nikolaus SchuetzAug 20, 2026
  4. t1401: check symbolic-ref exit codes and --quiet silenceNikolaus Schuetz via GitGitGadget, Aug 20, 2026
  5. Patrick SteinhardtAug 24, 2026
  6. Junio C HamanoAug 24, 2026
  7. Phillip WoodAug 24, 2026
  8. Nikolaus SchuetzAug 24, 2026
  9. Junio C HamanoAug 25, 2026
  10. t1401: check symbolic-ref failure and --quiet silence on a non-symbolic refNikolaus Schuetz via GitGitGadget, Aug 26, 2026
  11. Patrick SteinhardtAug 31, 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.