]> git.ipfire.org Git - thirdparty/git.git/commit
rev-parse: document how --is-* options work outside a repository
authorJunio C Hamano <gitster@pobox.com>
Wed, 1 May 2024 17:22:59 +0000 (10:22 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 1 May 2024 19:56:09 +0000 (12:56 -0700)
commitd424488901fffded2e3098eb4294b47e0391bc67
tree02e57afde9b6239c73eb4ddaebc0c57a9837fecb
parent0d464a4e6a5a19bd8fbea1deae22d48d14dccb01
rev-parse: document how --is-* options work outside a repository

When "git rev-parse" is run with the "--is-inside-work-tree" option
and friends outside a Git repository, the command exits with a
non-zero status and says "fatal: not a repository".  While it is not
wrong per-se, in the sense that it is useless to learn if we are
inside or outside a working tree in the first place when we are not
even in a repository, it could be argued that they should emit
"false" and exit with status 0, as they cannot possibly be "true".

As the current behaviour has been with us for a decade or more
since it was introduced in Git 1.5.3 timeframe, it is too late to
change it.

And arguably, the current behaviour is easier to use if you want to
distinguish among three states, i.e.,

 (1) the cwd is not controlled by Git at all
 (2) the cwd is inside a working tree
 (3) the cwd is not inside a working tree (e.g., .git/hooks/)

with a single invocation of the command by doing

    if inout=$(git rev-parse --is-inside-work-tree)
    then
        case "$inout" in
        true)   : in a working tree ;;
        false)  : not in a working tree ;;
        esac
    else
        : not in a repository
    fi

So, let's document clearly that the command will die() when run
outside a repository in general, unless in some special cases like
when the command is in the --parseopt mode.

While at it, update the introductory text that makes it sound as if
the primary operating mode is the only operating mode of the
command, which was written long before we added "--parseopt" and
"--sq-quote" modes.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-rev-parse.txt