Skip to content

Commit 1525b22

Browse files
committed
chore(hooks): enforce Signed-off-by line in commit messages
Add a commit-msg hook that requires a Signed-off-by line in all commit messages. This promotes contributor accountability and compliance with developer sign-off policies. Contributors are encouraged to use the `git commit -s` flag for all commits. Note: This hook does not verify if the commit is cryptographically signed; such validation should be performed in a post-commit hook if required. Signed-off-by: Gil Levkovich <[email protected]>
1 parent 1e14f80 commit 1525b22

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ repos:
1414
entry: contrib/scripts/conventional-commits
1515
language: script
1616
stages: [commit-msg]
17+
- id: signed-commit
18+
name: Signed Commit Enforcer
19+
entry: contrib/scripts/signed-commit
20+
language: script
21+
stages: [commit-msg]
1722

1823
- repo: https://github.com/pre-commit/pre-commit-hooks
1924
rev: v4.3.0

.pre-commit-hooks.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,12 @@
44
language: script
55
description: Conventional Commits Enforcement at the `git commit` client-side level
66
always_run: true
7-
stages: [commit-msg]
7+
stages: [commit-msg]
8+
9+
- id: signed-commit
10+
name: Signed Commit Enforcer
11+
entry: contrib/scripts/signed-commit
12+
language: script
13+
description: Ensures all commits contain a Signed-off-by line
14+
always_run: true
15+
stages: [commit-msg]

contrib/scripts/signed-commit

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
if [[ -z "$1" ]] || [[ ! -f "$1" ]]; then
4+
echo "ERROR: Commit message file not provided or does not exist."
5+
exit 1
6+
fi
7+
8+
# Check if signed-off-by line is present (automatically added using -s flag)
9+
if ! grep -q 'Signed-off-by:' "$1"; then
10+
echo "ERROR: Commit message must contain a Signed-off-by line."
11+
echo ""
12+
echo "To sign your commits, use the -s flag:"
13+
echo " git commit -s -m \"your commit message\""
14+
exit 1
15+
fi
16+
17+
exit 0

0 commit comments

Comments
 (0)