object-name: fix quiet @{u} parsing

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>

Felipe Contreras committed Mar 16, 2023 at 11:15 UTC dfbfdc521daece092a599959da79c3c134f26b3c
2 files changed +8 -2
object-name.c
+3 -2
@@ -898,6 +898,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
898 char *real_ref = NULL;
899 int refs_found = 0;
900 int at, reflog_len, nth_prior = 0;
901 + int fatal = !(flags & GET_OID_QUIETLY);
902
903 if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
904 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,
953
954 if (!len && reflog_len)
955 /* allow "@{...}" to mean the current branch reflog */
955 - refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, 0);
956 + refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, !fatal);
957 else if (reflog_len)
958 refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
959 else
959 - refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, 0);
960 + refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, !fatal);
961
962 if (!refs_found)
963 return -1;
t/t1507-rev-parse-upstream.sh
+5
@@ -183,6 +183,11 @@ test_expect_success '@{u} error message when no upstream' '
183 test_cmp expect actual
184 '
185
186 +test_expect_success '@{u} silent error when no upstream' '
187 + test_must_fail git rev-parse --verify --quiet @{u} 2>actual &&
188 + test_must_be_empty actual
189 +'
190 +
191 test_expect_success 'branch@{u} error message with misspelt branch' '
192 cat >expect <<-EOF &&
193 fatal: no such branch: ${SQ}no-such-branch${SQ}