git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCH] Make rev-parse -q and --is-* quiet

From
Jeff King <peff@peff.net>
Date
Mar 13, 2020, 17:52 UTC
Message-ID
<20200313175236.GB549554@coredump.intra.peff.net>
In-Reply-To
<4B2A0C64-FD4A-457C-A7CF-5B680AF38BC9@innova.no>
On Fri, Mar 13, 2020 at 12:13:52PM +0000, Erlend Aasland wrote:
Show 6 quoted lines
> 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
Previous: Erlend Aasland
Message 2 of 2 in “Make rev-parse -q and --is-* quiet”
  1. Make rev-parse -q and --is-* quietErlend Aasland, Mar 13, 2020
  2. Jeff KingMar 13, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.