-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Auto-configure TruffleHog for Pre-commit Hooks #4666
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Auto-configure TruffleHog for Pre-commit Hooks #4666
Conversation
MuneebUllahKhan222
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Well Done!
| // Pre-commit.com framework detection | ||
| // Docs: https://pre-commit.com/#pre-commit | ||
| // Sets PRE_COMMIT=1 environment variable when running hooks | ||
| if os.Getenv("PRE_COMMIT") == "1" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you link to a specific page in the docs that mentions this environment variable? I couldn't find it.
mustansir14
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I just have this one question regarding the PRE_COMMIT=1 env variable.
| return true | ||
| } | ||
|
|
||
| // Local Git hook detection (non-framework) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: It looks like you get these, if that's helpful:
GIT_AUTHOR_DATE=@1768568299 +0100
GIT_EXEC_PATH=/opt/homebrew/opt/git/libexec/git-core
GIT_INDEX_FILE=/Users/charliegunyon/code/hooks/.git/index.lock
Description:
This PR enhances TruffleHog to automatically detect when it's running as a pre-commit hook and configure itself with optimal settings. Users no longer need to manually specify multiple command-line flags for common pre-commit hook use cases.
Currently, when running TruffleHog as a pre-commit hook, users must manually specify several flags:
This PR enables TruffleHog to auto-detects pre-commit hook contexts and automatically applies the recommended configuration:
Auto-applied settings:
--since-commit HEAD- Scan only staged changes--fail- Exit if secrets are found (blocking commit)--trust-local-git-config--results=verified,unknownSupported Hook Frameworks
PRE_COMMIT=1environment variableHUSKY=1environment variableTRUFFLEHOG_PRE_COMMIT=1environment variable in your hook scriptChecklist:
make test-community)?make lintthis requires golangci-lint)?