Skip to content

Commit

Permalink
thanks to git rev-parse's new --show-toplevel flag, we can find the t…
Browse files Browse the repository at this point in the history
…op level more elegantly
  • Loading branch information
Dieterbe committed Dec 1, 2010
1 parent 7b3506f commit 32cb6d4
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions git-root
@@ -1,5 +1,7 @@
#!/bin/sh -e
# inspired by http://stackoverflow.com/questions/957928/is-there-a-way-to-get-to-the-git-root-directory-in-one-command/3009378#3009378
# gives absolute path to git repository root, either for cwd, or directory (or files' dirname) given as $1
# when not a git repository, exit >0
if [ -n "$1" ]
then
if [ -d "$1" ]
Expand All @@ -9,5 +11,4 @@ then
cd `dirname $1`
fi
fi
cdup=$(git rev-parse --show-cdup)
exec readlink -f ./$cdup
exec git rev-parse --show-toplevel

0 comments on commit 32cb6d4

Please sign in to comment.