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"

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