Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
REVIEW: Avoid loop to compute `$CHANGED_FILES`
Lorenz Leutgeb committed 25 days ago
commit 44adb953237fc9b2377a28b886c5acfa8eb847d7
parent 4999b763e687e466b1d30a049e1af80250728376
1 file changed +5 -7
modified scripts/git-hook-template.sh
@@ -3,15 +3,13 @@ set -e

HOOK_NAME=$(basename "$0")
SENSITIVE_FILES=("justfile" "build.rs" "rust-toolchain.toml")
-
CHANGED_FILES=()
BASE_BRANCH="master"

-
for file in "${SENSITIVE_FILES[@]}"; do
-
    # Check if the file differs between the base branch and the current working tree
-
    if git diff --name-only "$BASE_BRANCH" 2>/dev/null | grep -q "^${file}$"; then
-
        CHANGED_FILES+=("$file")
-
    fi
-
done
+
# Check which files were modified compared to the base branch.
+
mapfile -t CHANGED_FILES < <(comm -12 \
+
    <(git diff --name-only master | sort) \
+
    <(IFS=$'\n'; echo "${SENSITIVE_FILES[*]}" | sort) \
+
)

if [ ${#CHANGED_FILES[@]} -gt 0 ]; then
    echo "⚠️ WARNING: Sensitive files have been modified relative to $BASE_BRANCH."