diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d846a068..cdcb1cae 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -17,6 +17,15 @@ For starters, simply naming functions or global variables to reflect their actual intent will already be helpful. *Any* name is better than `sub_`, and can always be fixed or improved later. +## Setup + +Before committing anything, enable the Git hooks from the `hooks/` subdirectory +to automatically catch common mistakes: + +```shell +git config --local core.hooksPath hooks/ +``` + # Contribution guidelines ## Rule #1 diff --git a/hooks/pre-commit b/hooks/pre-commit new file mode 100644 index 00000000..d39327ba --- /dev/null +++ b/hooks/pre-commit @@ -0,0 +1,18 @@ +#!/bin/sh + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +# Remove trailing commas from `public` directives. These crash on TASM32 +# version 5.0, but work on later versions. +for f in `git diff-index --name-only --cached --diff-filter=ACMRX ${against} | grep \.asm$ -i`; do + if [ -n "$(sed -i -E 's/(public\s+[^;]+?),\s*(;.*)?$/\1\2/w /dev/stdout' "$f")" ]; then + echo "$f"': removed a trailing comma from a `public` line, please re-stage.' + exit 1 + fi +done