Change pre-commit hook to use temp directory
This commit is contained in:
parent
16334905ab
commit
1480cbbd96
1 changed files with 8 additions and 15 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue