SZEDER Gábor <szeder@xxxxxxxxxx> writes: > The __gitdir() helper function finds out the path of the git > repository by running 'git rev-parse --git-dir'. However, it has a > shortcut first to avoid the overhead of running a git command in a > subshell when the current directory is at the top of the work tree, > i.e. when it contains a '.git' subdirectory. > > If the 'GIT_DIR' environment variable is set then it specifies the > path to the git repository, and the autodetection of the '.git' > directory is not necessary. However, $GIT_DIR is only taken into > acocunt by 'git rev-parse --git-dir', and the check for the '.git' > subdirectory is performed first, so it wins over the path given in > $GIT_DIR. Strictly speaking, you have to be a bit careful here, though. If GIT_DIR is set as a shell variable without being exported, it will not affect where the "git" process you will spawn from your interactive shell session will find the repository. Only when it is exported it does. It is a different matter if the distinction matters in the real life, in other words, GIT_DIR set but not exported is a use case that is worth worrying about. But note that our own git-sh-setup script is one such use case, so I wouldn't be surprised if somebody uses it for a strange workflow (I suspect that might involve a working tree that has its .git dir in a totally unrelated place, and the user runs "GIT_DIR=$GIT_DIR git subcmd", using the set but not exported GIT_DIR as a typesaver). > diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh > index a6c9ce94..96468ceb 100755 > --- a/t/t9903-bash-prompt.sh > +++ b/t/t9903-bash-prompt.sh > @@ -85,7 +85,7 @@ test_expect_success 'gitdir - parent is a .git directory' ' > test_cmp expected "$actual" > ' > > -test_expect_failure 'gitdir - $GIT_DIR set while .git directory in cwd' ' > +test_expect_success 'gitdir - $GIT_DIR set while .git directory in cwd' ' > echo "$TRASH_DIRECTORY/otherrepo/.git" > expected && > ( > GIT_DIR="$TRASH_DIRECTORY/otherrepo/.git" && And it is a good thing that the next line that comes after the above context is "export GIT_DIR". If we were to declare "set but not exported" an uninteresting use case whose outcome is undefined (and that might be fine), this still tests the defined behaviour of having the GIT_DIR in the environment. -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html