Skip to content

Commit b2ff71a

Browse files
docs: add require-signed-commits hook and global git hook pattern (#2)
* feat: add require-signed-commits hook Checks commit.gpgsign=true and user.signingkey is set before allowing a commit. Blocks unsigned commits in non-interactive shells (e.g. agentic AI workflows) where signing can silently fall through. Usage in .pre-commit-config.yaml: - repo: https://github.com/injectedfusion/pre-commit-hooks rev: <tag> hooks: - id: require-signed-commits * fix: correct misleading comment and remove unused gpg_format variable * ci: add PR pipeline with shellcheck and Claude reviewer * docs: add require-signed-commits hook and global git hook pattern
1 parent 8356cf4 commit b2ff71a

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ Reusable [pre-commit](https://pre-commit.com/) hooks for GitOps, security, and m
99
| `check-branch-staleness` | Fail if branch is behind the default branch. Prevents stale commits in multi-agent or team workflows. |
1010
| `trivy-deps` | Scan dependency lockfiles for HIGH/CRITICAL CVEs. Catches what `trivy config` misses. |
1111
| `no-hardcoded-secrets` | Detect hardcoded passwords and API keys in YAML files. |
12+
| `require-signed-commits` | Block commits where `commit.gpgsign` is not `true` or `user.signingkey` is unset. |
1213

1314
## Usage
1415

@@ -30,6 +31,46 @@ pip install pre-commit # if not already installed
3031
pre-commit install
3132
```
3233

34+
## Personal hooks without per-repo setup
35+
36+
Some hooks (like `require-signed-commits`) enforce personal discipline that shouldn't be imposed on teammates. Use a global git hook instead — fires on every repo with zero per-repo setup:
37+
38+
```bash
39+
mkdir -p ~/.config/git/hooks
40+
git config --global core.hooksPath ~/.config/git/hooks
41+
```
42+
43+
Create `~/.config/git/hooks/pre-commit`:
44+
45+
```bash
46+
#!/usr/bin/env bash
47+
set -euo pipefail
48+
49+
# Personal check (e.g. signing)
50+
gpgsign="$(git config --get commit.gpgsign 2>/dev/null || echo 'false')"
51+
if [[ "$gpgsign" != "true" ]]; then
52+
echo "✗ Unsigned commit blocked: commit.gpgsign is not set to true"
53+
exit 1
54+
fi
55+
signingkey="$(git config --get user.signingkey 2>/dev/null || echo '')"
56+
if [[ -z "$signingkey" ]]; then
57+
echo "✗ Unsigned commit blocked: user.signingkey is not set"
58+
exit 1
59+
fi
60+
61+
# Chain to repo pre-commit config if present
62+
repo_root="$(git rev-parse --show-toplevel)"
63+
for config in "$repo_root/.pre-commit-config.local.yaml" "$repo_root/.pre-commit-config.yaml"; do
64+
if [[ -f "$config" ]]; then
65+
exec pre-commit run --config "$config" --hook-stage pre-commit
66+
fi
67+
done
68+
```
69+
70+
```bash
71+
chmod +x ~/.config/git/hooks/pre-commit
72+
```
73+
3374
## Hook Details
3475

3576
### check-branch-staleness

0 commit comments

Comments
 (0)