Last active
October 8, 2021 15:57
-
-
Save tsafin/1b1326eca583ef39f6b4d9d05e47f7a4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Hook to verify what modified lua files pass luacheck checks before got committed. | |
# Called by "git commit" with no arguments. | |
# To enable this hook, put it to `.git/hooks/pre-commit` and make it executable. | |
if git rev-parse --verify HEAD >/dev/null 2>&1 | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=$(git hash-object -t tree /dev/null) | |
fi | |
# Redirect output to stderr. | |
exec 1>&2 | |
gitroot=$(git rev-parse --show-toplevel) | |
modified_index=`git diff --cached --name-only --diff-filter=AM $against | grep '.lua$'` | |
if test ! -z "$modified_index" | |
then | |
cd $gitroot && luacheck --codes $modified_index || exit 1 | |
fi | |
exit 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
gitroot=$(git rev-parse --show-toplevel) | |
modified_index=`git diff --cached --name-only --diff-filter=AM | grep '.lua$'` | |
modified_not_index=`git diff --name-only --diff-filter=M | grep '.lua$'` | |
unique_list=$(cat <<EOF | sort | uniq | |
$modified_index | |
$modified_not_index | |
EOF | |
) | |
cd $gitroot | |
test ! -z "unique_list" && luacheck --codes $unique_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment