From: Benjamin C Meyer Date: Thu, 7 Nov 2013 01:40:06 +0000 (-0500) Subject: Behave much better when not in a git repository X-Git-Url: https://gitweb.fluxo.info/?a=commitdiff_plain;h=a7b60551d2fb4ce663f0b4fbc9b762c78c03cc8a;p=git-hooks.git Behave much better when not in a git repository or when the repository is a bare repository Signed-off-by: Benjamin C Meyer --- diff --git a/git-hooks b/git-hooks index e3f649b..fa08001 100755 --- a/git-hooks +++ b/git-hooks @@ -34,10 +34,14 @@ function hook_dirs hook="" fi echo "${HOME}/.git_hooks${hook}" - GITDIR=`git rev-parse --git-dir` - cd $GITDIR/.. - echo "${PWD}/git_hooks${hook}" - echo "${PWD}/.githooks${hook}" + git rev-parse --git-dir &> /dev/null + if [ $? -eq 0 ]; then + if [ $(git rev-parse --is-bare-repository) = 'false' ]; then + cd $(git rev-parse --show-toplevel) + echo "${PWD}/git_hooks${hook}" + echo "${PWD}/.githooks${hook}" + fi + fi eval echo "`git config hooks.global`"${hook} }