Blob Blame History Raw
#!/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"

# Empty means abort anyway
test -z "$(grep -vE '^#|^\s*$' "$commit_file")" && exit

git_dir=$(git rev-parse --git-dir)
test -f "$git_dir/MERGE_HEAD" && exit

err=0
new_refs=$(git diff-index -M -p --cached HEAD "patches.*/*" | \
	   awk -v FPAT='[^, ]+' \
	       '/^+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

if test "$err" != 0; then
    echo "Aborting."
    exit "$err"
fi