- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_precommit.sh
More file actions
Latest commit
executable file
·52 lines (45 loc) · 1.6 KB
/
Copy pathsetup_precommit.sh
File metadata and controls
executable file
·52 lines (45 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Setup script for pre-commit hooks
set -e
echo"🔧 Setting up pre-commit hooks for credential detection..."
# Check if pre-commit is installed
if!command -v pre-commit &> /dev/null;then
echo"📦 Installing pre-commit..."
pip install pre-commit
else
echo"✅ pre-commit already installed"
fi
# Install the git hooks
echo"🪝 Installing git hooks..."
pre-commit install
# Generate baseline for existing secrets (if any)
echo"📊 Scanning existing codebase for secrets..."
ifcommand -v detect-secrets &> /dev/null;then
detect-secrets scan --baseline .secrets.baseline
echo"✅ Baseline created/updated: .secrets.baseline"
else
echo"⚠️ detect-secrets not found, installing..."
pip install detect-secrets
detect-secrets scan --baseline .secrets.baseline
fi
# Run pre-commit on all files to check current state
echo"🔍 Running pre-commit checks on all files..."
pre-commit run --all-files || {
echo""
echo"⚠️ Some files failed pre-commit checks."
echo"This is normal on first run. Fix the issues and commit again."
exit 0
}
echo""
echo"✅ Pre-commit hooks successfully installed!"
echo""
echo"Usage:"
echo" • Hooks run automatically on 'git commit'"
echo" • Run manually: pre-commit run --all-files"
echo" • Update hooks: pre-commit autoupdate"
echo" • Skip hooks (NOT recommended): git commit --no-verify"
echo""
echo"Configuration files:"
echo" • .pre-commit-config.yaml - hook configuration"
echo" • .secrets.baseline - baseline for existing secrets"
echo" • pyproject.toml - Python tool configuration"