#!/bin/bash

# Don't allow changes to debian|ubuntu and stock tree in the same commit.

if git-rev-parse --verify HEAD > /dev/null 2>&1; then
	git-diff-index --name-only --cached HEAD
else
	# Ignore initial commits
	:
fi | (
ubuntu_changes=0
debian_changes=0
upstream_changes=0

while read file; do
	if echo $file | grep -q '^debian/'; then
		debian_changes=1
	elif echo $file | grep -q '^ubuntu/'; then
		ubuntu_changes=1
	else
		upstream_changes=1
	fi
done

exit_val=0

if test "$ubuntu_changes" = "1" -o "$upstream_changes" = "1" && \
	test "$debian_changes" = "1"; then
	echo "ABORT COMMIT: Cannot commit to debian/* and other code in the same commit" \
		1>&2
	exit_val=1
elif [ "$ubuntu_changes" = "1" -a "$upstream_changes" = "1" ]; then
	echo "ABORT COMMIT: Cannot commit to ubuntu/ and stock kernel in the same commit" \
		1>&2
	exit_val=1
fi

exit $exit_val
)
