mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-02-04 08:41:43 +05:30
feat(git): Use gitleaks in pre-commit git hook
This commit is contained in:
25
common/.config/templates/pre-commit
Executable file
25
common/.config/templates/pre-commit
Executable file
@@ -0,0 +1,25 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# An example hook script to verify what is about to be committed.
|
||||
# Called by "git commit" with no arguments. The hook should
|
||||
# exit with non-zero status after issuing an appropriate message if
|
||||
# it wants to stop the commit.
|
||||
#
|
||||
# To enable this hook, rename this file to "pre-commit".
|
||||
|
||||
# Check if Gitleaks is installed
|
||||
if ! command -v gitleaks > /dev/null 2>&1; then
|
||||
echo "Gitleaks is not installed. Skipping leak check."
|
||||
echo "Please install Gitleaks for enhanced security."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Run Gitleaks & check the exit code
|
||||
if ! gitleaks protect --staged -v; then
|
||||
echo "Gitleaks has detected potential secrets in your changes."
|
||||
echo "Please remove any sensitive information before committing."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# If Gitleaks passes, allow the commit
|
||||
exit 0
|
||||
Reference in New Issue
Block a user