`git rev-parse --is-inside-work-tree` and $GIT_WORK_TREE
- From
Elliott Cable <me@ell.io>
- Date
- Mar 29, 2016, 11:42 UTC
- Message-ID
- <CAPZ477NxXVNNwDvzaFt7GoUGuJwnOuX3y1N+aPtVRFD3E8dQBA@mail.gmail.com>
So, I find this behaviour a little strange; I can't determine if it's a subtle bug, or intentionally undefined/‘fuzzy’ behaviour:
$ cd a-repo/.git/
$ pwd
/path/to/a-repo/.git
$ git rev-parse --is-inside-work-tree
false
$ export GIT_WORK_TREE=/path/to/a-repo
$ git rev-parse --is-inside-work-tree
truei.e. when within the repository (the `.git` directory), and when that directory is a sub-directory of the working-tree, `rev-parse --is-inside-work-tree` reports *false* (reasonable enough, I suppose); but then if `$GIT_WORK_TREE` is set to precisely the directory that git was *already* assuming was the working-directory, then the same command, in the same location, reports *true*.
This should probably be made consistent: either `rev-parse --is-inside-work-tree` should report “true”, even inside the `.git` dir, as long as that directory is a sub-directory of the working-tree … or repository-directories / `$GIT_DIR` / `.git` directories should be excluded from truthy responses to `rev-parse --is-inside-work-tree`.
⁓ ELLIOTTCABLE — fly safe. http://ell.io/tt