git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Felipe Contreras <felipe.contreras@gmail.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Denton Liu" <liu.denton@gmail.com>,
	"Jonathan Tan" <jonathantanmy@google.com>
Subject: Re: [PATCH] object-name: fix quiet @{u} parsing
Date: Thu, 16 Mar 2023 10:43:55 -0700	[thread overview]
Message-ID: <xmqqfsa4lhgk.fsf@gitster.g> (raw)
In-Reply-To: <20230316171514.23741-1-felipe.contreras@gmail.com> (Felipe Contreras's message of "Thu, 16 Mar 2023 11:15:14 -0600")

Felipe Contreras <felipe.contreras@gmail.com> writes:

> 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>
> ---
>  object-name.c                 | 5 +++--
>  t/t1507-rev-parse-upstream.sh | 5 +++++
>  2 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/object-name.c b/object-name.c
> index 2dd1a0f56e..d9f3a176d8 100644
> --- a/object-name.c
> +++ b/object-name.c
> @@ -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;

All of the above look sensible.

> diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh
> index c34714ffe3..549eb315a9 100755
> --- a/t/t1507-rev-parse-upstream.sh
> +++ b/t/t1507-rev-parse-upstream.sh
> @@ -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
> +'

OK.  This does not check what comes out to the standard output
stream at all, and only cares that the standard error stream emits
nothing.  Which is absolutely the right thing to do.  When a command
exits non-zero, we do not guarantee what output it emits, and the
invoker is expected to check the exit status.

Will queue.  Thanks.

      reply	other threads:[~2023-03-16 17:44 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 17:15 [PATCH] object-name: fix quiet @{u} parsing Felipe Contreras
2023-03-16 17:43 ` Junio C Hamano [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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=xmqqfsa4lhgk.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=felipe.contreras@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=liu.denton@gmail.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).