diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index ac6971d9ee21..f4de6cbfa18b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -14,6 +14,11 @@ repos: entry: contrib/scripts/conventional-commits language: script stages: [commit-msg] + - id: signed-commit + name: Signed Commit Enforcer + entry: contrib/scripts/signed-commit + language: script + stages: [commit-msg] - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.3.0 diff --git a/.pre-commit-hooks.yaml b/.pre-commit-hooks.yaml index f239a0654aa4..a74044780178 100644 --- a/.pre-commit-hooks.yaml +++ b/.pre-commit-hooks.yaml @@ -4,4 +4,12 @@ language: script description: Conventional Commits Enforcement at the `git commit` client-side level always_run: true - stages: [commit-msg] \ No newline at end of file + stages: [commit-msg] + +- id: signed-commit + name: Signed Commit Enforcer + entry: contrib/scripts/signed-commit + language: script + description: Ensures all commits contain a Signed-off-by line + always_run: true + stages: [commit-msg] diff --git a/contrib/scripts/signed-commit b/contrib/scripts/signed-commit new file mode 100755 index 000000000000..1cd092d657be --- /dev/null +++ b/contrib/scripts/signed-commit @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +if [[ -z "$1" ]] || [[ ! -f "$1" ]]; then + echo "ERROR: Commit message file not provided or does not exist." + exit 1 +fi + +# Check if signed-off-by line is present (automatically added using -s flag) +if ! grep -q 'Signed-off-by:' "$1"; then + echo "ERROR: Commit message must contain a Signed-off-by line." + echo "" + echo "To sign your commits, use the -s flag:" + echo " git commit -s -m \"your commit message\"" + exit 1 +fi + +exit 0