diff --git a/hooks/pre-commit b/hooks/pre-commit index e02b7875..bb061b2c 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -4,14 +4,13 @@ set -e -# ensure we're in the appropriate git directory when invoked directly -# e.g. via `/etc/ngcp-config/.git/hooks/pre-commit` inside ngcpcfg -if ! git rev-parse --git-dir >/dev/null 2>&1 ; then - cd "$(dirname "${0}")" - if git rev-parse --git-dir >/dev/null 2>&1 ; then - git_dir="$(git rev-parse --git-dir)" - cd "$(dirname "${git_dir}")" - fi +# ensure we're in the appropriate git directory (/etc/ngcp-config/ by default), +# we don't rely on ${NGCPCTL_MAIN} just in case we're invoked directly, +# e.g. via `/etc/ngcp-config/.git/hooks/pre-commit` (outside of ngcpcfg) +cd "$(dirname "${0}")" +if git rev-parse --git-dir >/dev/null 2>&1 ; then + git_dir="$(git rev-parse --git-dir)" + cd "$(dirname "${git_dir}")" fi if ! git rev-parse --git-dir >/dev/null 2>&1 ; then