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.
This commit is contained in:
Talia 2022-08-10 08:49:22 +02:00
parent ea8e512482
commit 71e8ebbed5
1 changed files with 7 additions and 6 deletions

View File

@ -4,7 +4,8 @@ filter=$(git config hooks.filter)
validate=$(git config hooks.validate) validate=$(git config hooks.validate)
indentation=$(git config hooks.indentation) indentation=$(git config hooks.indentation)
temp=$(mktemp -p /dev/shm -d -t git-hook.XXXX) 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() { new() {
git status --porcelain | grep -E '^AM|^M|^A' | sed 's/^[^ ]* *//' git status --porcelain | grep -E '^AM|^M|^A' | sed 's/^[^ ]* *//'
@ -26,7 +27,7 @@ git checkout-index --prefix="$temp/index/" --all
cd $temp/index/ cd $temp/index/
if [ -n "$filter" ]; then if [ -n "$filter" ]; then
ln -s $GIT_DIR/ .git ln -s $WORK_DIR/.git/ .git
sh -c "$filter" sh -c "$filter"
git add --all git add --all
rm .git rm .git
@ -70,14 +71,14 @@ if [ -n "$error" ]
then exit 1 then exit 1
fi fi
cd $GIT_DIR cd $WORK_DIR/.git
rm -rf $temp rm -rf $temp
hook=$(basename $0) hook=$(basename $0)
if [ -f "$GIT_DIR/hooks/$hook" ] if [ -f "$WORK_DIR/.git/hooks/$hook" ]
then then
echo Running project-level hook: $GIT_DIR/hooks/$hook echo Running project-level hook: $WORK_DIR/.git/hooks/$hook
$GIT_DIR/hooks/$hook $WORK_DIR/.git/hooks/$hook
error=$? error=$?
if [ -n "$error" ] if [ -n "$error" ]
then exit $error then exit $error