]> gitweb.fluxo.info Git - git-hooks.git/commitdiff
Behave much better when not in a git repository
authorBenjamin C Meyer <ben@meyerhome.net>
Thu, 7 Nov 2013 01:40:06 +0000 (20:40 -0500)
committerBenjamin C Meyer <ben@meyerhome.net>
Thu, 7 Nov 2013 02:51:19 +0000 (21:51 -0500)
or when the repository is a bare repository

Signed-off-by: Benjamin C Meyer <ben@meyerhome.net>
git-hooks

index e3f649b943574afcba4adf779769bf12f15a1c36..fa080019afa34fc4d3a191c8de69d9d9c588ab1f 100755 (executable)
--- 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}
 }