Skip to content

Commit 8069aa0

Browse files
committed
Merge branch 'fc/oid-quietly-parse-upstream'
"git rev-parse --quiet foo@{u}", or anything that asks @{u} to be parsed with GET_OID_QUIETLY option, did not quietly fail, which has been corrected. * fc/oid-quietly-parse-upstream: object-name: fix quiet @{u} parsing
2 parents 6041a13 + dfbfdc5 commit 8069aa0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

object-name.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
899899
char *real_ref = NULL;
900900
int refs_found = 0;
901901
int at, reflog_len, nth_prior = 0;
902+
int fatal = !(flags & GET_OID_QUIETLY);
902903

903904
if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
904905
if (warn_ambiguous_refs && warn_on_object_refname_ambiguity) {
@@ -953,11 +954,11 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
953954

954955
if (!len && reflog_len)
955956
/* allow "@{...}" to mean the current branch reflog */
956-
refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, 0);
957+
refs_found = repo_dwim_ref(r, "HEAD", 4, oid, &real_ref, !fatal);
957958
else if (reflog_len)
958959
refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
959960
else
960-
refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, 0);
961+
refs_found = repo_dwim_ref(r, str, len, oid, &real_ref, !fatal);
961962

962963
if (!refs_found)
963964
return -1;

t/t1507-rev-parse-upstream.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,11 @@ test_expect_success '@{u} error message when no upstream' '
183183
test_cmp expect actual
184184
'
185185

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+
186191
test_expect_success 'branch@{u} error message with misspelt branch' '
187192
cat >expect <<-EOF &&
188193
fatal: no such branch: ${SQ}no-such-branch${SQ}

0 commit comments

Comments
 (0)