Merge rust-bitcoin/rust-bitcoin#3081: githooks: Added post-merge githook to check if hooks changed

a7fa237d32 githooks: Added post-merge githook to check if hooks changed (Ryan Breen)

Pull request description:

  Referring back to [this post](https://github.com/rust-bitcoin/rust-bitcoin/pull/2980#discussion_r1673140172) in #2980, there was discussion that a post-merge githook should be added to check if the user's copied githooks have changed.

  In order to distinguish between a githook that a user installed themselves and a rust-bitcoin githook, I chose to add a tag at the beginning of the project's hooks.

ACKs for top commit:
  Kixunil:
    ACK a7fa237d32
  apoelstra:
    ACK a7fa237d32 I have never used `git pull` but I also have not ever used githooks, so I guess this is good

Tree-SHA512: 90314fea81a93e5a2c698fad4837f7661dd90f9fb2ecd015cbe6472fbef8647e06a1595e2aab4f557a1cc770050b828d430eabda04500954c0e4c9995098237c
This commit is contained in:
merge-script 2024-07-27 16:23:47 +00:00
commit a4a84f4c1b
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 36 additions and 0 deletions

35
githooks/post-merge Executable file
View File

@ -0,0 +1,35 @@
#!/usr/bin/env bash
# === RUST-BITCOIN GITHOOK ===
# Scan the githooks after merge. If the user is using any of the rust-bitcoin githooks and they have changed, let them know
# to rerun the githooks setup.
# We only care about this on master
[[ "$(git branch --show-current)" = "master" ]] || exit
# Get the local githooks directory, regardless of configuration.
GIT_DIR=$(git rev-parse --git-common-dir)
HOOKS_DIR=$(git config --get core.hooksPath || echo "$GIT_DIR/hooks")
# Scan each of the hooks looking for the tag. If the tag is found, then the user is using a
# rust-bitcoin githook. We should compare them to the repo's hooks to see if they have
# changed in the latest git pull.
for hook in "$HOOKS_DIR"/*
do
if grep -q '=== RUST-BITCOIN GITHOOK ===' "$hook"; then
BN=$(basename "$hook")
if ! cmp --quiet "$hook" "githooks/$BN"; then
>&2 cat <<- EOF
==================================================
Project githooks have changed. Please inspect the
changes and re-reun \`just githooks-install\` if
they are legitimate.
Remove $HOOKS_DIR/post-merge to skip this warning
in the future.
==================================================
EOF
exit
fi
fi
done

View File

@ -1,4 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# === RUST-BITCOIN GITHOOK ===
# #
# Verify what is about to be committed. Called by "git commit" with no # Verify what is about to be committed. Called by "git commit" with no
# arguments. The hook should exit with non-zero status after issuing an # arguments. The hook should exit with non-zero status after issuing an