From 3c543bba54f0d1d274eabad748fa773a1d619557 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 27 Nov 2017 12:19:04 +0000 Subject: [PATCH] run commit hook on what we're committing (#356) (rather than what's in our WC) --- hooks/pre-commit | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hooks/pre-commit b/hooks/pre-commit index ae96b9ce..6f98b813 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -2,4 +2,21 @@ set -eu +# make the GIT_DIR and GIT_INDEX_FILE absolute, before we change dir +export GIT_DIR=$(readlink -f `git rev-parse --git-dir`) +if [ -n "${GIT_INDEX_FILE:+x}" ]; then + export GIT_INDEX_FILE=$(readlink -f "$GIT_INDEX_FILE") +fi + +# create a temp dir. The `trap` incantation will ensure that it is removed +# again when this script completes. +tmpdir=`mktemp -d` +trap 'rm -rf "$tmpdir"' EXIT +cd "$tmpdir" + +# get a clean copy of the index (ie, what has been `git add`ed), so that we can +# run the checks against what we are about to commit, rather than what is in +# the working copy. +git checkout-index -a + ./scripts/find-lint.sh fast