On Mon, Apr 15, 2024 at 9:58 AM Toru Okugawa <castor.4bit@xxxxxxxxx> 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 > > What did you expect to happen? (Expected behavior) > > If the current working directory is outside the work tree, the > documentation says that `git rev-parse --is-inside-work-tree` will > output false. > https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---is-inside-work-tree I think this is working as intended, but the documentation is lacking or misleading. With very few exceptions[1], `git rev-parse` expects to be run either within a Git working tree or within a Git repository (i.e. the .git/ directory or a bare repository). Options such as --is-inside-work-tree, --is-bare-repository, etc. are meant to report upon aspects of the worktree or repository in which the command is invoked. Looking at the source code for `git rev-parse`, it does appear that it has explicit support for the case of checking whether or not the current directory is a Git worktree or repository. The way to do that is to run `git rev-parse` without any arguments. However, even in that case, it will print the "fatal: not a git repository" error. 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 [1]: --sh-quote, --parse-opt, --local-env-vars, --resolve-git-dir