Skip to content

Instantly share code, notes, and snippets.

@akanieski
Created June 22, 2023 22:45
Show Gist options
  • Save akanieski/d778dadd8d5159e721ad39a90e948252 to your computer and use it in GitHub Desktop.
Save akanieski/d778dadd8d5159e721ad39a90e948252 to your computer and use it in GitHub Desktop.
GitLeaks Pre-Commit Hook
#!/bin/sh
#
# Define color codes
RED='\033[0;31m'
LIGHT_GREEN='\033[1;32m'
NC='\033[0m' # No Color
if command -v podman &> /dev/null; then
export cli='podman'
else
if command -v docker &> /dev/null; then
export cli='docker'
fi
fi
$cli run -v ${PWD}:/path ghcr.io/gitleaks/gitleaks:latest protect --source="/path" -v
if [ $? -ne 0 ]; then
echo "${RED}ABORTING GIT COMMIT DUE TO SECRETS FOUND ABOVE! ${NC}"
echo "If you would like to ignore these specific commits, copy their fingerprint into the .gitleaksignore file."
exit 1
else
echo "${LIGHT_GREEN}No Secrets Found.${NC}"
exit 0
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment