Reputation: 4190
From a script, how to determine the current GIT_DIR? If not overriden, it's just the top level dir or the top level dir of a bare repo.
I want something like:
[/git/repo1/subdir]$ git show-git-dir
/git/repo1/.git
Upvotes: 9
Views: 1237
Reputation: 689
Here is a pure bash version, and will find the directory when you are in the root. (Ikke's solution is better by the way).
a=$PWD
while [ "$a" != "" ] && [ "$a" != '/' ];
do
a=`dirname $a`;
if [ -d $a/.git ];
then
echo "$a";
break;
fi
done
On windows you will probably have to add another [ "$a" != '\' ] to test for that case, and I dont have access at the moment to check if the bash shell that comes with Msysgit supports "dirname".
But works in Terminator on Ubuntu.
Upvotes: 0