From f24b329ef5994d09b1ecba996c439150e3af8195 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 28 Apr 2022 22:37:34 -0400 Subject: pre-commit hook that only checks modifed files --- bin/git-pre-commit-hook | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100755 bin/git-pre-commit-hook (limited to 'bin/git-pre-commit-hook') diff --git a/bin/git-pre-commit-hook b/bin/git-pre-commit-hook new file mode 100755 index 00000000..2a65775a --- /dev/null +++ b/bin/git-pre-commit-hook @@ -0,0 +1,22 @@ +#!/bin/bash + +# copy (DO NOT SYMLINK) this file to .git/hooks/pre-commit +# to check style on all modified files before allowing the commit to complete +# +# DO NOT SYMLINK +# DO NOT SYMLINK +# DO NOT SYMLINK (why? security risk) + +cd $(dirname "$0")/../.. + +IFS=$'\n' +files=( $(git diff-index --cached --name-only --diff-filter=AMCR HEAD) ) + +if [ "${#files}" -gt 0 ]; then + errors=$(bin/style-check "${files[@]}" 2>&1) + + if [ "$?" != "0" ]; then + echo "$errors" + exit 1 + fi +fi -- cgit v1.2.3 From 1140be3cefcf070b03fd219c64a1f015db5ef510 Mon Sep 17 00:00:00 2001 From: Lex Neva Date: Thu, 28 Apr 2022 22:53:19 -0400 Subject: only check style on lines changed by commit --- bin/git-pre-commit-hook | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'bin/git-pre-commit-hook') diff --git a/bin/git-pre-commit-hook b/bin/git-pre-commit-hook index 2a65775a..81ace2cd 100755 --- a/bin/git-pre-commit-hook +++ b/bin/git-pre-commit-hook @@ -9,14 +9,9 @@ cd $(dirname "$0")/../.. -IFS=$'\n' -files=( $(git diff-index --cached --name-only --diff-filter=AMCR HEAD) ) +errors=$(git diff --cached | bin/style-check --diff 2>&1) -if [ "${#files}" -gt 0 ]; then - errors=$(bin/style-check "${files[@]}" 2>&1) - - if [ "$?" != "0" ]; then - echo "$errors" - exit 1 - fi +if [ "$?" != "0" ]; then + echo "$errors" + exit 1 fi -- cgit v1.2.3