-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/bin/bash | ||
|
||
# pre-push hook script | ||
# This script checks the files in commits being pushed for prohibited patterns | ||
# and exits with status 2 if such patterns are found. | ||
|
||
REMOTE="$1" | ||
URL="$2" | ||
|
||
# Find the range of commits to be pushed | ||
read LOCAL_REF LOCAL_SHA REMOTE_REF REMOTE_SHA | ||
|
||
# Exit if the range can't be determined | ||
if [ "$LOCAL_SHA" = "0000000000000000000000000000000000000000" ]; then | ||
echo "Nothing to push. Exiting." | ||
exit 0 | ||
fi | ||
|
||
if [ "$REMOTE_SHA" = "0000000000000000000000000000000000000000" ]; then | ||
# Push to new branch or repo, analyze all commits | ||
RANGE="$LOCAL_SHA" | ||
else | ||
# Standard push, analyze commits in the range | ||
RANGE="$REMOTE_SHA..$LOCAL_SHA" | ||
fi | ||
|
||
# Get the list of files changed in the range | ||
FILES=$(git diff --name-only "$RANGE") | ||
|
||
# Patterns to search for | ||
PATTERNS=( | ||
"BRCM:[0-9]+:proprietary:" | ||
"BRCM:[0-9]+:NONE:RED" | ||
"Broadcom Proprietary and Confidential" | ||
) | ||
|
||
# Check each file | ||
for FILE in $FILES; do | ||
if [ -f "$FILE" ]; then | ||
FILE_CONTENT=$(git show "$LOCAL_REF:$FILE" 2>/dev/null || echo "") | ||
for PATTERN in "${PATTERNS[@]}"; do | ||
if echo "$FILE_CONTENT" | grep -E -q "$PATTERN"; then | ||
echo "Prohibited pattern found in file: $FILE" | ||
echo "Pattern: $PATTERN" | ||
echo "Push blocked due to prohibited content." | ||
exit 2 | ||
fi | ||
done | ||
fi | ||
done | ||
|
||
# Allow the push to proceed | ||
echo "No prohibited content found. Push allowed." | ||
exit 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" |