Merge rust-bitcoin/rust-bitcoin#2980: just: install/remove git hooks

1b0653314b just: install/remove git hooks (Ryan Breen)

Pull request description:

  Added `just install-git-hooks` and `just remove-git-hooks` (with contrib script). Fix: #2599

ACKs for top commit:
  Kixunil:
    ACK 1b0653314b
  tcharding:
    ACK 1b0653314b

Tree-SHA512: fa11eb3429a91928de43be94223862fd1805b7328a61e098cf3fad89fd6df4f6818eaa4b2eeea432e1f0b16c6df12c5fcca66389236af915113d49f1ac2741f8
This commit is contained in:
merge-script 2024-07-14 15:03:11 +00:00
commit ac490bf347
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
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