mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-21 02:20:43 +08:00
scripts, build, just: POSIX Compliance
Enforce POSIX shell syntax with ShellCheck using `--shell sh`.
This commit is contained in:
@@ -1,35 +1,35 @@
|
||||
#! /usr/bin/env bash
|
||||
#! /usr/bin/env sh
|
||||
set -euo pipefail
|
||||
|
||||
readonly HOOK="${HOOK:-$(basename "$0")}"
|
||||
|
||||
if ! [[ "$HOOK" =~ ^(pre-(commit|push)|post-checkout|commit-msg)$ ]]
|
||||
then
|
||||
echo "Unknown hook '${HOOK}'."
|
||||
exit 1
|
||||
fi
|
||||
case "$HOOK" in
|
||||
pre-commit|pre-push|post-checkout|commit-msg) ;;
|
||||
*)
|
||||
echo "Unknown hook '${HOOK}'."
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
readonly SENSITIVE_FILES=("justfile" "build.rs" "rust-toolchain.toml")
|
||||
readonly BASE_BRANCH="main"
|
||||
|
||||
# Check which files were modified compared to the base branch.
|
||||
mapfile -t CHANGED_FILES < <(comm -12 \
|
||||
<(git diff --name-only "${BASE_BRANCH}" | sort) \
|
||||
<(IFS=$'\n'; echo "${SENSITIVE_FILES[*]}" | sort) \
|
||||
)
|
||||
# Check which sensitive files were modified compared to the base branch.
|
||||
CHANGED_FILES=$(git diff --name-only "$BASE_BRANCH" -- \
|
||||
justfile build.rs rust-toolchain.toml)
|
||||
|
||||
if [ ${#CHANGED_FILES[@]} -gt 0 ]
|
||||
if [ -n "$CHANGED_FILES" ]
|
||||
then
|
||||
echo "⚠️ WARNING: Sensitive files have been modified relative to $BASE_BRANCH."
|
||||
echo "Executing this hook may run arbitrary code from the modified files."
|
||||
echo ""
|
||||
|
||||
git --no-pager diff "$BASE_BRANCH" -- "${SENSITIVE_FILES[@]}"
|
||||
git --no-pager diff "$BASE_BRANCH" -- justfile build.rs rust-toolchain.toml
|
||||
|
||||
# Read from /dev/tty because stdin is not attached to the terminal in Git hooks.
|
||||
exec < /dev/tty
|
||||
|
||||
read -r -p "⚠️ Do you want to continue executing the '${HOOK}' hook? [y/N] " response
|
||||
printf "⚠️ Do you want to continue executing the '%s' hook? [y/N] " "$HOOK"
|
||||
read -r response
|
||||
case "$response" in
|
||||
[yY][eE][sS]|[yY])
|
||||
echo "Continuing with '${HOOK}' hook…"
|
||||
|
||||
Reference in New Issue
Block a user