From 4167eeee448f16c6e4ee5e218f9ca45ce1c9a95e Mon Sep 17 00:00:00 2001 From: cora Date: Sun, 30 Jul 2023 18:59:21 +0200 Subject: [PATCH] Add optional pre-commit hook to tools/ --- tools/git-pre-commit-hook | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 tools/git-pre-commit-hook diff --git a/tools/git-pre-commit-hook b/tools/git-pre-commit-hook new file mode 100755 index 000000000..ec07e8080 --- /dev/null +++ b/tools/git-pre-commit-hook @@ -0,0 +1,20 @@ +#!/bin/bash +# stolen from https://gist.github.com/Gethe/bbcc180770eb9edeebaf83c96844c5df + +# copy file to .git/hooks/pre-commit +# needs bash and luacheck installed + +exitCode= +for file in $(git diff --cached --name-only | grep -E '\.lua$'); do + # we only want to check the staged changes, not any un-staged changes + if [[ -f "$file" ]]; then + luacheck "$file" --formatter plain + fi + + if [[ $? -eq 1 ]]; then + # we want to go through all files before we exit, so just store it for now + exitCode=1 + fi +done + +exit $exitCode