diff --git a/README.md b/README.md index 52b736cd0..e54097d2e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/contrib/copy-githooks.sh b/contrib/copy-githooks.sh new file mode 100755 index 000000000..13632db55 --- /dev/null +++ b/contrib/copy-githooks.sh @@ -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) diff --git a/justfile b/justfile index 4bc6a7e2f..962dcbf17 100644 --- a/justfile +++ b/justfile @@ -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