Skip to content

Instantly share code, notes, and snippets.

@tsafin
Last active October 8, 2021 15:57
Show Gist options
  • Save tsafin/1b1326eca583ef39f6b4d9d05e47f7a4 to your computer and use it in GitHub Desktop.
Save tsafin/1b1326eca583ef39f6b4d9d05e47f7a4 to your computer and use it in GitHub Desktop.
#!/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
#!/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