tools: Add pre-hook script

This commit is contained in:
Antonio Aloisio 2025-01-08 23:40:26 +01:00
parent 2a1834aad2
commit c5e2d877be
2 changed files with 38 additions and 0 deletions

28
scripts/hooks/pre-commit Executable file
View file

@ -0,0 +1,28 @@
#!/bin/bash
echo "Checking source file for broadcom proprietary files..."
pattern1='BRCM:[0-9]+:proprietary:'
pattern2='BRCM:[0-9]+:NONE:RED'
files=$(git diff --cached --name-only --diff-filter=ACM | grep -E '\.(c|h)$')
if [ -z "$files" ]; then
# No .c or .h files staged, exit successfully
exit 0
fi
echo "Checking files:"
for file in $files; do
echo "* $file"
if git show ":$file" | grep -Eq "$pattern1|$pattern2"; then
echo "Error: File '$file' contains forbidden patterns."
echo "Patterns:"
echo " - $pattern1"
echo " - $pattern2"
echo "Commit aborted."
exit 1
fi
done
# If no matches are found, allow the commit
exit 0

10
scripts/install-hooks.sh Executable file
View file

@ -0,0 +1,10 @@
#!/bin/bash
REPO_BASE=$(git rev-parse --show-toplevel)
SCRIPT_DIR="$REPO_BASE/scripts/hooks"
INSTALL_DIR="$REPO_BASE/.git/hooks"
echo "Repository base directory:$REPO_BASE"
mkdir -p "$INSTALL_DIR"
cp -a "${SCRIPT_DIR}"/* "${INSTALL_DIR}"
echo "All webhooks have been copied"