Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions hooks/pre-commit
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#!/bin/bash

## This hook provides an example that prevents the API Key from being committed.
## The file can be adapted to your needs, but ultimately this hook will reject the commit if the MAPS_API_KEY
## has been modified. Git Hooks are located in the folder .git/hooks
## This hook rejects the commit if any staged change adds a Google Maps API key.
## Install it by copying this file to .git/hooks/pre-commit.

FILE="local.defaults.properties"
API_KEY_REGEX="AIza[0-9A-Za-z\-_]{35}"
API_KEY_REGEX='AIza[0-9A-Za-z_-]{35}'

if grep -qE "^MAPS_API_KEY=$API_KEY_REGEX" "$FILE"; then
echo "Error: Commit rejected. Invalid content in $FILE."
if git diff --cached -U0 --no-color | grep -E '^\+' | grep -qE "$API_KEY_REGEX"; then
echo "Error: Commit rejected. A staged change contains a Google Maps API key."
exit 1
fi

exit 0
exit 0
Loading