diff --git a/scripts/git-commit-msg b/scripts/git-commit-msg new file mode 100755 index 0000000..5adcd80 --- /dev/null +++ b/scripts/git-commit-msg @@ -0,0 +1,43 @@ +#!/bin/bash +############################################################################# +# Copyright (c) 2024 SUSE +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of version 2 of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, contact Novell, Inc. +# +# To contact SUSE about this file by physical or electronic mail, +# you may find current contact information at www.suse.com +############################################################################# + +commit_file="$1" + +err=0 +git diff-index --name-status --diff-filter=AM --cached HEAD | ( +while read stat file garbage; do + case "$file" in + patches.*/*) + new_refs=$(git diff-index -p --cached HEAD "$file" | \ + awk '/^+References:/ {for (i=2; i <= NF; i++) refs[$i]++} + /^-References:/ {for (i=2; i <= NF; i++) refs[$i]--} + END { for (r in refs) if (refs[r] > 0) print(r)}') + for ref in $new_refs ; do + grep -q $ref $commit_file || { echo "New reference '$ref' missing in the commit message." ; err=1 ; } + done + ;; + esac +done + +if test "$err" != 0; then + echo "Aborting." + exit "$err" +fi ) || exit diff --git a/scripts/install-git-hooks b/scripts/install-git-hooks index 349a944..5ecb9ec 100755 --- a/scripts/install-git-hooks +++ b/scripts/install-git-hooks @@ -124,11 +124,16 @@ install_scripts() { chmod +x "$GIT_DIR"/hooks/pre-commit ln -rfs "$SCRIPTS_DIR"/git-pre-commit "$GIT_DIR"/hooks/kernel-source-pre-commit - if test -r "$GIT_DIR"/hooks/pre-merge-commit ; then - echo "Cannot install pre-merge-commit hook, upstream your hook to kernel-source/scripts" - else - ln -rfs "$GIT_DIR"/hooks/pre-commit "$GIT_DIR"/hooks/pre-merge-commit - fi + declare -A hooks + hooks[pre-merge-commit]="$GIT_DIR"/hooks/pre-commit + hooks[commit-msg]="$SCRIPTS_DIR"/git-commit-msg + for h in ${!hooks[@]} ; do + if test -f "$GIT_DIR"/hooks/$h -a ! -L "$GIT_DIR"/hooks/$h ; then + echo "Cannot install $h hook, upstream your hook to kernel-source/scripts" + else + ln -rfs "${hooks[$h]}" "$GIT_DIR"/hooks/$h + fi + done } case "$1" in