Commit 1b7e4d9b authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Added hook-scripts directory for pre-made scripts

Added hook-scripts/update directory for pre-made hook scripts. Two
update scripts included.
parent d3e5c7b8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@

gitcore_SCRIPTS = .bindir/git-hooks
pkgdata_SCRIPTS = run-hooks arg_parse_functions string_functions
SUBDIRS = hook-scripts


.bindir/git-hooks: git-hooks | .bindir
+5 −1
Original line number Diff line number Diff line
@@ -21,4 +21,8 @@ AM_INIT_AUTOMAKE
gitcoredir=`git --exec-path`
AC_SUBST([gitcoredir])

AC_OUTPUT([Makefile])
AC_CONFIG_FILES(
    [Makefile]
    [hook-scripts/Makefile]
    )
AC_OUTPUT
+21 −0
Original line number Diff line number Diff line
#
#  Copyright (C) 2013  Dom Sekotill
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  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, see <http://www.gnu.org/licenses/>.
#


nobase_pkgdata_SCRIPTS = \
	update/ref-locks \
	update/whitespace-errors
+36 −0
Original line number Diff line number Diff line
#! /bin/bash

inc ()
{
	local branch=$1 new=$2 namespace
	shift; shift
	cd locks
	while [ "$1" ]; do
		cd $1 || break
		namespace=${namespace:+$namespace/}$1
		shift
	done 2>/dev/null

	if [ -e $1 ]; then
		e=$'\e'
		echo
		echo "Cannot update $branch"
		echo "Reason:"
		cat $1 | sed -e "s/^/$e[1;31m  /" -e "s/$/$e[m/"
		echo
	elif [ -e .lock ] && [ $new = true ] && ! [ -e .ignore-$1 ]; then
		echo
		echo "Cannot create new references under $namespace"
		echo "Only references under the following namespaces can be created here:"
		find -mindepth 1 -maxdepth 1 -type d -printf "  $namespace/%P\n"
		echo
	else
		exit 0
	fi

	exit 1
}

IFS=/ read -a parts <<< "$1"
[ $((0x$2)) -eq 0 ] && new=true || new=false
inc $1 $new "${parts[@]}"
+93 −0
Original line number Diff line number Diff line
#! /bin/bash
# vim: set ts=2 sw=2:

REF="$1"
OLD="$2"
NEW="$3"

# Don't check tags
[[ $REF =~ ^refs/tags ]] && exit 0

[[ 0x$NEW -eq 0 ]] && exit
[[ 0x$OLD -eq 0 ]] && OLD=`git rev-list --simplify-by-decoration --max-count=1 $NEW`

if [ "$OLD" != "$NEW" ]; then
	gitdiff () { git diff $OLD..$NEW "$@"; }
else
	gitdiff () { git show $NEW --pretty=format: "$@"; }
fi

RETURN_STATUS=0
trap 'exit $RETURN_STATUS' EXIT


# $e for the escape character
e=$'\e'


filter()
{
	# filter(regex, desc)
	#
	# Define a filter
	#
	# Arguments:
	#  regex  - a regex compatible with egrep that matches added lines in
	#           the git diff of all the commits being filtered
	#  desc   - a short description of the filter that is used in the
	#           output in the form "The following files have <desc>"
	#           eg. "trailing whitespace"

	local regex="$1" desc="$2" failed_files=()
	unset failed

	if [ x$found_files = x ]; then
		IFS=$'\n' changed_files=( `gitdiff --name-only` )
		found_files=yes
	fi

	for file in "${changed_files[@]}"; do
		if gitdiff -- "$file" | sed -n 's/^+\($\|[^+]\)/\1/p' | egrep -q "$regex"; then
			failed_files=( "${failed_files[@]}" "$file" )
			failed=yes
		fi
	done

	if ! [ x$failed = x ]; then
		RETURN_STATUS=1

		if [ x$message_started = x ]; then
			message_started=yes
			cat <<-END_MESSAGE

				$e[1;31mREJECTED:$e[m
				Some code changes you are committing include lines that have
				disallowed whitespace.

				For code cleanliness blank lines should have no whitespace
				and lines with printed characters may not have more than one
				space character at the end (this is to accomodate vim's line
				wrapping).

				Please remove any lines containing unwanted whitespace from
				your modified code.

			END_MESSAGE
		fi

		echo "The following files have $desc:"
		pattern="  \e[%i;1m%s\e[m\n"
		if [ ${#failed_files[@]} -gt 0 ]; then
			printf "  \e[31;1m%s\e[m\n" "${failed_files[@]}"
		else
			printf "  \e[32;1mNo files\e[m\n"
		fi
		echo

	fi
}


# Place filters here
filter '^[[:space:]]+$' 'whitespace filled lines'
filter '[[:graph:]][[:space:]]{2,}$' 'trailing whitespace'