]> git.ipfire.org Git - thirdparty/git.git/commitdiff
object-name: fix quiet @{u} parsing
authorFelipe Contreras <felipe.contreras@gmail.com>
Thu, 16 Mar 2023 17:15:14 +0000 (11:15 -0600)
committerJunio C Hamano <gitster@pobox.com>
Thu, 16 Mar 2023 17:44:56 +0000 (10:44 -0700)
Currently `git rev-parse --quiet @{u}` is not actually quiet when
upstream isn't configured:

  fatal: no upstream configured for branch 'foo'

Make it so.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
object-name.c
t/t1507-rev-parse-upstream.sh

index 2dd1a0f56e1e442dec47dfbbcdd46d58aecc812c..d9f3a176d89662b45fbb32dbd9bf1d3faaea5793 100644 (file)
@@ -898,6 +898,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
        char *real_ref = NULL;
        int refs_found = 0;
        int at, reflog_len, nth_prior = 0;
+       int fatal = !(flags & GET_OID_QUIETLY);
 
        if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
                if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
@@ -952,11 +953,11 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
 
        if (!len && reflog_len)
                /* allow "@{...}" to mean the current branch reflog */
-               refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, 0);
+               refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, !fatal);
        else if (reflog_len)
                refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
        else
-               refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, 0);
+               refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, !fatal);
 
        if (!refs_found)
                return -1;
index c34714ffe3fbe5545da1d05b9a74cfc6113e43dd..549eb315a9037845e1dedea14ccb16b943714649 100755 (executable)
@@ -183,6 +183,11 @@ test_expect_success '@{u} error message when no upstream' '
        test_cmp expect actual
 '
 
+test_expect_success '@{u} silent error when no upstream' '
+       test_must_fail git rev-parse --verify --quiet @{u} 2>actual &&
+       test_must_be_empty actual
+'
+
 test_expect_success 'branch@{u} error message with misspelt branch' '
        cat >expect <<-EOF &&
        fatal: no such branch: ${SQ}no-such-branch${SQ}