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

Re: Re* Unexpected behavior with the rev-parse operation

From
Toru Okugawa <castor.4bit@gmail.com>
Date
Apr 30, 2024, 14:26 UTC
Message-ID
<CANHPH19FCWUAMZLFZEY+_+zv0KUkuVGNQS26WmEPjnPtjrK8KQ@mail.gmail.com>
In-Reply-To
<xmqqedap2ijk.fsf_-_@gitster.g>
On Mon, Apr 29, 2024 at 8:07 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 68 quoted lines
>
> Eric Sunshine <sunshine@sunshineco.com> writes:
>
> > On Mon, Apr 15, 2024 at 9:58 AM Toru Okugawa <castor.4bit@gmail.com> wrote:
> >> I have encountered some unexpected behavior with the rev-parse operation.
> >> ---
> >> $ ls -a
> >> .  ..
> >> $ git rev-parse --is-inside-work-tree
> >> fatal: not a git repository (or any of the parent directories): .git
> >> ...
> > ... This
> > means it is your responsibility, as a script writer, to suppress or
> > capture the error message (whichever is appropriate for your case).
> > For instance:
> >
> >     if test git rev-parse >/dev/null 2>&1
> >     then
> >         echo "in a Git directory or repository"
> >     else
> >         echo "not in a Git directory or repository"
> >     fi
>
> All true.  It may however need some documentation updates, though,
> something along this line, perhaps?
>
>  Documentation/git-rev-parse.txt | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
>
> diff --git c/Documentation/git-rev-parse.txt w/Documentation/git-rev-parse.txt
> index f9d5a35fa0..a62d798744 100644
> --- c/Documentation/git-rev-parse.txt
> +++ w/Documentation/git-rev-parse.txt
> @@ -18,8 +18,16 @@ Many Git porcelainish commands take a mixture of flags
>  (i.e. parameters that begin with a dash '-') and parameters
>  meant for the underlying 'git rev-list' command they use internally
>  and flags and parameters for the other commands they use
> -downstream of 'git rev-list'.  This command is used to
> -distinguish between them.
> +downstream of 'git rev-list'.  One purpose of this command is to
> +allow calling programs to distinguish between them.
> +
> +There are a few other operation modes that have noting to do with
> +the above "help parse command line options" added to the command.
> +
> +Unless otherwise specified, most of the options and operation modes
> +require you to run this command inside a git repository or a working
> +tree that is under control of a git repository, and will give you a
> +fatal error otherwise.
>
>
>  OPTIONS
> @@ -32,11 +40,15 @@ Each of these options must appear first on the command line.
>
>  --parseopt::
>         Use 'git rev-parse' in option parsing mode (see PARSEOPT section below).
> +       The command in this mode can be used outside a repository or
> +       a working tree controlled by a repository.
>
>  --sq-quote::
>         Use 'git rev-parse' in shell quoting mode (see SQ-QUOTE
>         section below). In contrast to the `--sq` option below, this
>         mode only does quoting. Nothing else is done to command input.
> +       The command in this mode can be used outside a repository or
> +       a working tree controlled by a repository.
>
>  Options for --parseopt
>  ~~~~~~~~~~~~~~~~~~~~~~
Thank you for your responses.

I'm aware that `--is-inside-work-tree` is an option for `git rev-parse`, and I understand that it is normal for the command to generate an error when executed outside a Git repository. Indeed, I have previously used the result of `git rev-parse >/dev/null 2>&1` to determine whether the directory is inside a Git repository or not.

However, if determining the presence of a Git repository by checking for errors is the appropriate approach, I'm interested in understanding the intended use of the `--is-inside-work-tree` option. I had thought it was meant to suppress errors in exceptional cases.

Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 6 in “Unexpected behavior with the rev-parse operation”
  1. Toru OkugawaApr 15, 2024
  2. Eric SunshineApr 28, 2024
  3. Re* Unexpected behavior with the rev-parse operationJunio C Hamano, Apr 28, 2024
  4. Toru OkugawaApr 30, 2024
  5. Junio C HamanoApr 30, 2024
  6. Toru OkugawaMay 1, 2024

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.