From 71e8ebbed5e6f43d50adc5edaf6c7985b6f00ca4 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Wed, 10 Aug 2022 08:49:22 +0200 Subject: [PATCH] Add WORK_DIR variable to pre-commit hook This is necessary to allow validations &c. to easily run uncommitted or ignored scripts from the working directory. --- githooks/pre-commit | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/githooks/pre-commit b/githooks/pre-commit index 6ae13c4..014a154 100755 --- a/githooks/pre-commit +++ b/githooks/pre-commit @@ -4,7 +4,8 @@ filter=$(git config hooks.filter) validate=$(git config hooks.validate) indentation=$(git config hooks.indentation) temp=$(mktemp -p /dev/shm -d -t git-hook.XXXX) -export GIT_DIR=$(git rev-parse --show-toplevel)/.git +export SRC_DIR=$(pwd) +export WORK_DIR=$(git rev-parse --show-toplevel) new() { git status --porcelain | grep -E '^AM|^M|^A' | sed 's/^[^ ]* *//' @@ -26,7 +27,7 @@ git checkout-index --prefix="$temp/index/" --all cd $temp/index/ if [ -n "$filter" ]; then - ln -s $GIT_DIR/ .git + ln -s $WORK_DIR/.git/ .git sh -c "$filter" git add --all rm .git @@ -70,14 +71,14 @@ if [ -n "$error" ] then exit 1 fi -cd $GIT_DIR +cd $WORK_DIR/.git rm -rf $temp hook=$(basename $0) -if [ -f "$GIT_DIR/hooks/$hook" ] +if [ -f "$WORK_DIR/.git/hooks/$hook" ] then - echo Running project-level hook: $GIT_DIR/hooks/$hook - $GIT_DIR/hooks/$hook + echo Running project-level hook: $WORK_DIR/.git/hooks/$hook + $WORK_DIR/.git/hooks/$hook error=$? if [ -n "$error" ] then exit $error