just: Rename `HOOK_NAME` to just `HOOK`

This commit is contained in:
Lorenz Leutgeb 2026-04-15 20:59:46 +02:00 committed by Fintan Halpenny
parent 112c901de8
commit fc12414778
1 changed files with 10 additions and 18 deletions

View File

@ -1,11 +1,11 @@
#! /usr/bin/env bash #! /usr/bin/env bash
set -euo pipefail set -euo pipefail
readonly HOOK_NAME="$(basename "$0")" readonly HOOK="${HOOK:-$(basename "$0")}"
if ! [[ "$HOOK_NAME" =~ ^(pre-(commit|push)|post-checkout)$ ]] if ! [[ "$HOOK" =~ ^(pre-(commit|push)|post-checkout)$ ]]
then then
echo "Unknown hook '${HOOK_NAME}'." echo "Unknown hook '${HOOK}'."
exit 1 exit 1
fi fi
@ -18,7 +18,8 @@ mapfile -t CHANGED_FILES < <(comm -12 \
<(IFS=$'\n'; echo "${SENSITIVE_FILES[*]}" | sort) \ <(IFS=$'\n'; echo "${SENSITIVE_FILES[*]}" | sort) \
) )
if [ ${#CHANGED_FILES[@]} -gt 0 ]; then if [ ${#CHANGED_FILES[@]} -gt 0 ]
then
echo "⚠️ WARNING: Sensitive files have been modified relative to $BASE_BRANCH." echo "⚠️ WARNING: Sensitive files have been modified relative to $BASE_BRANCH."
echo "Executing this hook may run arbitrary code from the modified files." echo "Executing this hook may run arbitrary code from the modified files."
echo "" echo ""
@ -28,26 +29,17 @@ if [ ${#CHANGED_FILES[@]} -gt 0 ]; then
# Read from /dev/tty because stdin is not attached to the terminal in Git hooks. # Read from /dev/tty because stdin is not attached to the terminal in Git hooks.
exec < /dev/tty exec < /dev/tty
read -r -p "⚠️ Do you want to continue executing the '${HOOK_NAME}' hook? [y/N] " response read -r -p "⚠️ Do you want to continue executing the '${HOOK}' hook? [y/N] " response
case "$response" in case "$response" in
[yY][eE][sS]|[yY]) [yY][eE][sS]|[yY])
echo "Continuing with '${HOOK_NAME}' hook..." echo "Continuing with '${HOOK}' hook…"
;; ;;
*) *)
echo "Skipping '${HOOK_NAME}' hook." echo "Skipping '${HOOK}' hook."
exit 0 exit 0
;; ;;
esac esac
fi fi
# Execute the appropriate just recipe based on the hook name just "$HOOK"
if [ "$HOOK_NAME" = "pre-commit" ]; then
just pre-commit
elif [ "$HOOK_NAME" = "pre-push" ]; then
just pre-push
elif [ "$HOOK_NAME" = "post-checkout" ]; then
just post-checkout
else
echo "⚠️ Unknown hook: $HOOK_NAME"
exit 1
fi