From 1480cbbd96836ac3a2ab9cef8485088fbdcdd6e4 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Mon, 25 Jan 2021 13:22:31 +0100 Subject: [PATCH] Change pre-commit hook to use temp directory --- githooks/pre-commit | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/githooks/pre-commit b/githooks/pre-commit index e083cfe..c669f74 100755 --- a/githooks/pre-commit +++ b/githooks/pre-commit @@ -1,22 +1,13 @@ #!/bin/sh indentation=$(git config hooks.indentation) +temp=$(mktemp -p /dev/shm -d -t git-hook.XXXX) +export GIT_DIR=$(git rev-parse --show-toplevel)/.git new() { git status --porcelain | grep -E '^AM|^M|^A' | sed 's/^[^ ]* *//' } -prepare() { - index=$(git write-tree) > /dev/null - git stash push --keep-index --include-untracked > /dev/null -} - -reset() { - git checkout stash -- '*' - git stash drop > /dev/null - git read-tree "$index" -} - check() { file=$2 luajit -e " @@ -28,22 +19,21 @@ check() { end" } +git checkout-index --prefix="$temp/index/" --all + +cd $temp/index/ case $indentation in tab|tabs) - prepare echo "Checking tab indentation" for file in $(new); do check '\t' $file || error=1 done - reset ;; space|spaces) - prepare echo "Checking space indentation" for file in $(new); do check ' ' $file || error=1 done - reset ;; ""|off) echo "Skipping indentation check" @@ -54,6 +44,9 @@ case $indentation in ;; esac +cd $GIT_DIR +rm -rf $temp + if [ -z "$error" ] then exit 0 else exit 1