diff --git a/.envrc b/.envrc index 6dff70de7..62060ff14 100644 --- a/.envrc +++ b/.envrc @@ -2,3 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 use flake +pre-commit install +pre-commit install -t prepare-commit-msg diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 785facb72..65e169643 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -57,3 +57,11 @@ repos: - id: markdownlint exclude: ^paper\.md$ args: [-r, "~MD013,~MD033,~MD024"] + + - repo: local + hooks: + - id: dco-hook + name: check DCO + entry: ./tools/pre-commit-dco-hook.sh + language: script + stages: [prepare-commit-msg] diff --git a/tools/pre-commit-dco-hook.sh b/tools/pre-commit-dco-hook.sh new file mode 100755 index 000000000..7cfc630c7 --- /dev/null +++ b/tools/pre-commit-dco-hook.sh @@ -0,0 +1,17 @@ +#!/bin/sh +# +# Append a Signed-off-by line to all git commit messages +# +# Author: Philipp Jungkamp +# SPDX-FileCopyrightText: 2014-2025 Institute for Automation of Complex Power Systems, RWTH Aachen University +# SPDX-License-Identifier: Apache-2.0 + +MESSAGE_FILE="$1" +GIT_AUTHOR="$(git var GIT_AUTHOR_IDENT | sed -n 's|^\(.*>\).*$|\1|p')" +SIGNOFF="Signed-off-by: $GIT_AUTHOR" + +if ! grep --quiet --fixed-strings --line-regexp "$SIGNOFF" "$MESSAGE_FILE" ; then + printf "\n%s" "$SIGNOFF" >> "$MESSAGE_FILE" +fi + +exit 0