Skip to content

Conversation

@kashifkhan0771
Copy link
Contributor

@kashifkhan0771 kashifkhan0771 commented Jan 14, 2026

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:

trufflehog git file://. --since-commit HEAD --fail --trust-local-git-config --results=verified,unknown

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,unknown

Supported Hook Frameworks

  1. pre-commit.com - Automatically detected via PRE_COMMIT=1 environment variable
  2. Husky - Automatically detected via HUSKY=1 environment variable
  3. Native Git Hooks - Set TRUFFLEHOG_PRE_COMMIT=1 environment variable in your hook script

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@kashifkhan0771 kashifkhan0771 requested a review from a team January 14, 2026 10:29
Copy link
Contributor

@MuneebUllahKhan222 MuneebUllahKhan222 left a 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" {
Copy link
Contributor

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.

Copy link
Contributor

@mustansir14 mustansir14 left a 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)
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants