Skip to content

Commit a27351b

Browse files
committed
chore(hooks): add commit-msg hook to enforce Signed-off-by line in commit messages
Although our documentation instructs users to configure their .gitconfig with `gpgsign = true` under the [commit] section, we cannot rely solely on this setting. Users may misconfigure their environment, and third-party contributors might not follow these instructions. This commit introduces a commit-msg hook that checks for the presence of a `Signed-off-by:` line in the commit message. The hook does not verify the actual presence of a cryptographic signature. It only checks for the text. We assume the line is auto-generated by git when using the `-s` flag. A malicious user could bypass this check by manually adding the line, but our goal is to encourage best practices, not to enforce cryptographic validation. Signed-off-by: Gil Levkovich <[email protected]>
1 parent 8b1a2fe commit a27351b

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-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: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
12
- id: conventional-commits
23
name: Conventional Commits Minder
34
entry: contrib/scripts/conventional-commits
45
language: script
56
description: Conventional Commits Enforcement at the `git commit` client-side level
67
always_run: true
7-
stages: [commit-msg]
8+
stages: [commit-msg]
9+
10+
- id: signed-commit
11+
name: Signed Commit Enforcer
12+
entry: contrib/scripts/signed-commit
13+
language: script
14+
description: Ensures all commits contain a Signed-off-by line
15+
always_run: true
16+
stages: [commit-msg]

contrib/scripts/signed-commit

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
if ! grep -q '^Signed-off-by:' "$1"; then
9+
echo "ERROR: Commit message must contain a Signed-off-by line."
10+
echo ""
11+
echo "To sign your commits, use the -s flag:"
12+
echo " git commit -s -m 'your commit message'"
13+
exit 1
14+
fi

0 commit comments

Comments
 (0)