Matthias Brugger c8a553
#!/bin/bash
Michal Marek 0a417c
#############################################################################
Michal Marek b3020a
# Copyright (c) 2008,2009,2015 Novell, Inc.
Michal Marek 0a417c
# All Rights Reserved.
Michal Marek 0a417c
#
Michal Marek 0a417c
# This program is free software; you can redistribute it and/or
Michal Marek 0a417c
# modify it under the terms of version 2 of the GNU General Public License as
Michal Marek 0a417c
# published by the Free Software Foundation.
Michal Marek 0a417c
#
Michal Marek 0a417c
# This program is distributed in the hope that it will be useful,
Michal Marek 0a417c
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Michal Marek 0a417c
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.   See the
Michal Marek 0a417c
# GNU General Public License for more details.
Michal Marek 0a417c
#
Michal Marek 0a417c
# You should have received a copy of the GNU General Public License
Michal Marek 0a417c
# along with this program; if not, contact Novell, Inc.
Michal Marek 0a417c
#
Michal Marek 0a417c
# To contact Novell about this file by physical or electronic mail,
Michal Marek 0a417c
# you may find current contact information at www.novell.com
Michal Marek 0a417c
#############################################################################
Michal Marek 9bee79
#
Michal Marek 5073e1
# to be run from the pre-commit hook, runs check-patch{hdr,fmt} on every added
Michal Marek 5073e1
# or modified file in patches.*/
Michal Marek 9bee79
Michal Marek b3020a
for dir in "$(git rev-parse --show-cdup)" "" "../"; do
Michal Marek b3020a
        dir="${dir}scripts"
Michal Marek b3020a
	if test -x "$dir/check-patchfmt"; then
Michal Marek b3020a
		break
Michal Marek b3020a
	fi
Michal Marek b3020a
done
Michal Marek b3020a
Michal Marek b3020a
tmp=$(mktemp /tmp/check-patch.XXXXXXXXXX)
Michal Marek b3020a
trap "rm -f $tmp" EXIT
Michal Marek b3020a
Michal Marek 9bee79
err=0
Michal Marek 825cdd
git diff-index --name-status --diff-filter=AM --cached HEAD | (
Michal Marek 825cdd
while read stat file garbage; do
Jeff Mahoney 6ddf1b
    update=
Jeff Mahoney 6ddf1b
    if [ "$stat" = "M" ]; then
Jeff Mahoney 6ddf1b
	update="--update"
Jeff Mahoney 6ddf1b
    fi
Jeff Mahoney 6ddf1b
Michal Marek 9bee79
    case "$file" in
Michal Marek 9bee79
    patches.*/*)
Michal Marek b3020a
        git cat-file blob :$file >"$tmp"
Michal Suchanek 616eff
	if [ -z "$(diffstat -p1 -l "$tmp")" ] ; then
Michal Suchanek 616eff
		echo "$file" is empty patch
Michal Suchanek 616eff
		err=1
Michal Suchanek 616eff
	fi
Jeff Mahoney 6ddf1b
        "$dir/check-patchhdr" $update --stdin "$file" <"$tmp" || err=1
Michal Marek 070ebe
        "$dir/check-patchfmt" --stdin "$file" <"$tmp" || err=1
Michal Suchanek 0dea23
	"$dir/check-patch-blacklist" $(dirname "$dir")/blacklist.conf "$file" <$tmp || err=1
Michal Marek 9bee79
    esac
Michal Marek 9bee79
done
Benjamin Poirier 869e9a
Jeff Mahoney 9e192a
config_sh="$dir/../rpm/config.sh"
Jeff Mahoney 9e192a
series_conf="$dir/../series.conf"
Jeff Mahoney 9e192a
Benjamin Poirier 27a005
if [ -r "$config_sh" ]; then
Benjamin Poirier 27a005
	. "$config_sh"
Benjamin Poirier 27a005
fi
Benjamin Poirier 27a005
Benjamin Poirier 27a005
if [ "$SORT_SERIES" = "yes" -a -r "$series_conf" ] && \
Benjamin Poirier 27a005
	! "$dir/git_sort/pre-commit.sh"; then
Benjamin Poirier 27a005
	err=1
Benjamin Poirier 869e9a
fi
Benjamin Poirier 869e9a
Michal Marek 9bee79
if test "$err" != 0; then
Michal Marek 9bee79
    echo "Aborting."
Michal Marek 9bee79
    exit "$err"
Michal Marek 825cdd
fi ) || exit