Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
git-hook-template: Avoid loop to compute `$CHANGED_FILES`
Lorenz Leutgeb committed 22 days ago
commit 2d99d41211c03a2aa710d38f924fa5878a083b79
parent b5b77e2b63702d0c1d0099f569a26a72c5fbe39d
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