TT#86451 hooks/pre-commit: ensure to always execute in main ngcpcfg directory

When `ngcpcfg commit ...` is executed from inside a git repository as
its working directory (like `/etc/`), then the initial `git rev-parse
--git-dir` invocation does *not* fail.

This results in not switching into the appropriate main directory
(`/etc/ngcp-config/`), but instead continue to run in the working
directory and create the .ngcpcfg_perms at the wrong place (like `/etc/`
instead of `/etc/ngcp-config/`).

Change-Id: Ic9da1f306274d3ba1d9d97dfe77e39094aa2127a
changes/14/41814/2
Michael Prokop 6 years ago
parent 75c08e8180
commit faf696416b

@ -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

Loading…
Cancel
Save