git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nikolaus Schuetz via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
	Nikolaus Schuetz <nikolauspschuetz@gmail.com>,
	Nikolaus Schuetz <nikolauspschuetz@gmail.com>
Subject: [PATCH v2] t1401: check symbolic-ref exit codes and --quiet silence
Date: Thu, 20 Aug 2026 22:20:02 +0000	[thread overview]
Message-ID: <pull.2204.v2.git.1787264402361.gitgitgadget@gmail.com> (raw)
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 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.

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.

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-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2204/nikolauspschuetz/ns/t1401-symbolic-ref-quiet-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/2204

Range-diff vs v1:

 1:  345e664a52 ! 1:  22694da869 t1401: test symbolic-ref exit codes on a non-symbolic ref
     @@ Metadata
      Author: Nikolaus Schuetz <nikolauspschuetz@gmail.com>
      
       ## Commit message ##
     -    t1401: test symbolic-ref exit codes on a non-symbolic ref
     +    t1401: check symbolic-ref exit codes and --quiet silence
      
          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 was not tested.
     +    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.
      
     -    Check that querying a non-symbolic ref exits 128 with the usual
     -    "is not a symbolic ref" message, and that --quiet instead exits 1
     -    with no output.
     +    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.
      
          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 2>err &&
     ++	test_expect_code 128 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 2>err &&
     ++	test_expect_code 1 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..6fad83ade8 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 with exit code 128' '
+	test_expect_code 128 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_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

      parent reply	other threads:[~2026-08-20 22:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-13 21:12 [PATCH] t1401: test symbolic-ref exit codes on a non-symbolic ref Nikolaus Schuetz via GitGitGadget
2026-08-19 11:25 ` Patrick Steinhardt
2026-08-20 15:13   ` Nikolaus Schuetz
2026-08-20 22:20 ` Nikolaus Schuetz via GitGitGadget [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.2204.v2.git.1787264402361.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=nikolauspschuetz@gmail.com \
    --cc=ps@pks.im \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).