[Contributing] Remove trailing commas from `public` in a pre-commit hook

Starting more ore less simple with a shell script calling `sed`, which
should work anywhere Git is used.
This commit is contained in:
nmlgc 2023-03-20 01:29:50 +01:00
parent 0685bd0885
commit e7a9262f50
2 changed files with 27 additions and 0 deletions

View File

@ -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_<something>`, 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

18
hooks/pre-commit Normal file
View File

@ -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