diff --git a/.husky/prepare-commit-msg b/.husky/prepare-commit-msg new file mode 100755 index 0000000000..46bbdc8905 --- /dev/null +++ b/.husky/prepare-commit-msg @@ -0,0 +1,30 @@ +#!/usr/bin/env bash +# SPDX-FileCopyrightText: 2026 SAP SE or an SAP affiliate company and Juno contributors +# SPDX-License-Identifier: Apache-2.0 +# .husky/prepare-commit-msg +# +# Auto-append a Signed-off-by trailer using the committer's git identity, +# satisfying the DCO check. Skips merge/squash/amend commits and is a no-op +# if the trailer is already present. + +COMMIT_MSG_FILE="$1" +COMMIT_SOURCE="$2" + +case "$COMMIT_SOURCE" in + merge|squash|commit) exit 0 ;; +esac + +NAME="$(git config user.name)" +EMAIL="$(git config user.email)" + +if [ -z "$NAME" ] || [ -z "$EMAIL" ]; then + exit 0 +fi + +TRAILER="Signed-off-by: $NAME <$EMAIL>" + +if grep -qFx "$TRAILER" "$COMMIT_MSG_FILE"; then + exit 0 +fi + +git interpret-trailers --if-exists addIfDifferent --trailer "$TRAILER" --in-place "$COMMIT_MSG_FILE"