Skip to content

Commit dfbfdc5

Browse files
felipecgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7556e5d commit dfbfdc5

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
@@ -898,6 +898,7 @@ static int get_oid_basic(struct repository *r, const char *str, int len,
898898
char *real_ref = NULL;
899899
int refs_found = 0;
900900
int at, reflog_len, nth_prior = 0;
901+
int fatal = !(flags & GET_OID_QUIETLY);
901902

902903
if (len == r->hash_algo->hexsz && !get_oid_hex(str, oid)) {
903904
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,
952953

953954
if (!len && reflog_len)
954955
/* 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);
956957
else if (reflog_len)
957958
refs_found = repo_dwim_log(r, str, len, oid, &real_ref);
958959
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);
960961

961962
if (!refs_found)
962963
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)