git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Erlend Aasland <Erlend-A@innova.no>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [RFC PATCH] Make rev-parse -q and --is-* quiet
Date: Fri, 13 Mar 2020 13:52:36 -0400	[thread overview]
Message-ID: <20200313175236.GB549554@coredump.intra.peff.net> (raw)
In-Reply-To: <4B2A0C64-FD4A-457C-A7CF-5B680AF38BC9@innova.no>

On Fri, Mar 13, 2020 at 12:13:52PM +0000, Erlend Aasland wrote:

> If rev-parse is called with both -q and an --is-* option, the result is
> provided as the return code of the command, iso. printed to stdout.
> 
> This simplifies using these queries in shell scripts:
> git rev-parse --is-bare-repository && do_stuff
> git rev-parse --is-shallow-repository && do_stuff

I left some comments in the other part of the thread, but another
potential downside here is that the exit code also tells us whether the
command was unable to run for unrelated reasons (i.e., the answer is
really a tristate: yes, no, or "we don't know the answer").

One obvious reason to exit non-zero would be that we're not in a
repository at all. I _think_ that works OK with all of these
conditionals, because if we're not in a repo, then we are obviously not
inside a git-dir, and so on.

Another reason is that the caller misspelled the option name. :) That
might be an acceptable risk, though. It's not like it isn't present in
other commands, probably people are doing:

  test "$(git rev-parse --is-whatever") = "true" && do_stuff

anyway, which has the same problem. Though perhaps the simplicity there
is an argument that we don't need the new exit-code mechanism.

-Peff

  reply	other threads:[~2020-03-13 17:52 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13 12:13 [RFC PATCH] Make rev-parse -q and --is-* quiet Erlend Aasland
2020-03-13 17:52 ` Jeff King [this message]
  -- strict thread matches above, loose matches on Subject: below --
2020-03-13 17:30 Abhishek Kumar
2020-03-13 17:47 ` Jeff King
2020-03-13 18:18   ` Junio C Hamano
2020-03-13 19:10     ` Erlend Aasland
2020-03-13 17:50 ` Eric Sunshine

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=20200313175236.GB549554@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=Erlend-A@innova.no \
    --cc=git@vger.kernel.org \
    /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).