From 47853d3ab1f51be283f150667066de9de0d24f0f Mon Sep 17 00:00:00 2001 From: Jan Schlicht Date: Fri, 21 Feb 2020 10:04:38 +0100 Subject: [PATCH] Add a pre-commit hook to check for signed-off commits (#1168) Signed-off-by: Jan Schlicht --- .pre-commit-config.yaml | 18 ++++++++++++++++-- hack/check-commit-signed-off.sh | 14 ++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100755 hack/check-commit-signed-off.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1ef7baa5d..20e165026 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,19 @@ +# Git hooks for KUDO. Install with +# pre-commit install -t pre-commit -t commit-msg repos: - - repo: git://github.com/golangci/golangci-lint - rev: v1.22.0 + - repo: local hooks: - id: golangci-lint + name: golangci-lint + description: Check that source code is linted + entry: make lint + language: system + stages: [commit] + - repo: local + hooks: + - id: signed-off-commits + name: signed-off-commits + description: Check that commit messages include a 'Signed-off-by' line + entry: ./hack/check-commit-signed-off.sh + language: script + stages: [commit-msg] diff --git a/hack/check-commit-signed-off.sh b/hack/check-commit-signed-off.sh new file mode 100755 index 000000000..f48a6965c --- /dev/null +++ b/hack/check-commit-signed-off.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +file="$1" + +signedoff_regex='^Signed-off-by: ' + +if [ "$(grep -c "$signedoff_regex" "$file")" != "1" ]; then + printf >&2 "Signed-off-by line is missing.\n" + exit 1 +fi