just: install/remove git hooks

This commit is contained in:
Ryan Breen 2024-07-08 00:05:42 -04:00
parent 6c8f759676
commit 1b0653314b
3 changed files with 43 additions and 8 deletions

View File

@ -185,14 +185,8 @@ fixing `act` issues.
### Githooks
To assist devs in catching errors _before_ running CI we provide some githooks. If you do not
already have locally configured githooks you can use the ones in this repository by running, in the
root directory of the repository:
```
git config --local core.hooksPath githooks/
```
Alternatively add symlinks in your `.git/hooks` directory to any of the githooks we provide.
To assist devs in catching errors _before_ running CI we provide some githooks. Copy the hooks in `githooks/`
to your githooks folder or run `just githooks-install` to copy them all.
## Policy on Altcoins/Altchains

33
contrib/copy-githooks.sh Executable file
View File

@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -euo pipefail
GIT_DIR=$(git rev-parse --git-common-dir)
HOOKS_DIR=$(git config --get core.hooksPath || echo "$GIT_DIR/hooks")
remove_githooks() {
for hook in githooks/*
do
bn=$(basename "$hook")
echo "Removing githook $bn"
rm "$HOOKS_DIR/$bn"
done
exit 0
}
add_githooks() {
mkdir -p "$HOOKS_DIR"
cp -i githooks/* "$HOOKS_DIR"
exit 0
}
while getopts "r" flag; do
case $flag in
r) remove_githooks
;;
*) exit 1
;;
esac
done
add_githooks # Copy githooks by default (no options provided)

View File

@ -40,3 +40,11 @@ sane: lint
# Update the recent and minimal lock files.
update-lock-files:
contrib/update-lock-files.sh
# Install githooks
githooks-install:
./contrib/copy-githooks.sh
# Remove githooks
githooks-remove:
./contrib/copy-githooks.sh -r