Skip to content

Commit d424488

Browse files
committed
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 <[email protected]>
1 parent 0d464a4 commit d424488

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

Documentation/git-rev-parse.txt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,15 @@ Many Git porcelainish commands take a mixture of flags
1818
(i.e. parameters that begin with a dash '-') and parameters
1919
meant for the underlying 'git rev-list' command they use internally
2020
and flags and parameters for the other commands they use
21-
downstream of 'git rev-list'. This command is used to
22-
distinguish between them.
21+
downstream of 'git rev-list'. The primary purpose of this command
22+
is to allow calling programs to distinguish between them. There are
23+
a few other operation modes that have nothing to do with the above
24+
"help parse command line options".
25+
26+
Unless otherwise specified, most of the options and operation modes
27+
require you to run this command inside a git repository or a working
28+
tree that is under the control of a git repository, and will give you
29+
a fatal error otherwise.
2330

2431

2532
OPTIONS
@@ -32,11 +39,15 @@ Each of these options must appear first on the command line.
3239

3340
--parseopt::
3441
Use 'git rev-parse' in option parsing mode (see PARSEOPT section below).
42+
The command in this mode can be used outside a repository or
43+
a working tree controlled by a repository.
3544

3645
--sq-quote::
3746
Use 'git rev-parse' in shell quoting mode (see SQ-QUOTE
3847
section below). In contrast to the `--sq` option below, this
3948
mode only does quoting. Nothing else is done to command input.
49+
The command in this mode can be used outside a repository or
50+
a working tree controlled by a repository.
4051

4152
Options for --parseopt
4253
~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)