#!/bin/sh
#
# Copyright (c) 2006, 2008 Junio C Hamano
#
# The "pre-rebase" hook is run just before "git rebase" starts doing
# its job, and can prevent the command from running by exiting with
# non-zero status.
#
# The hook is called with the following parameters:
#
# $1 -- the upstream the series was forked from.
# $2 -- the branch being rebased (or empty when rebasing the current branch).
#
# This sample shows how to prevent topic branches that are already
# merged to 'next' branch from getting rebased, because allowing it
# would result in rebasing already published history.

basebranch="$1"
if test "$#" = 2
then
	topic="refs/heads/$2"
else
	topic=`git symbolic-ref HEAD` ||
	exit 0 ;# we do not interrupt rebasing detached HEAD
fi

full_br=`git symbolic-ref HEAD`
branch=${full_br##refs/heads/}

# Now we are dealing with a topic branch being rebased
# on top of master.  Is it OK to rebase it?

# Does the topic really exist?
git show-ref -q "$topic" || {
	echo >&2 "No such branch $topic"
	exit 1
}

# get delta from master and look for template leftovers there:
git log $branch --not --remotes=*/master -- | grep -q "FirstName LastName"
if [ $? -eq 0 ]; then
	echo "***********************************************************" >&2
	echo "**** WARNING! **** WARNING **** WARNING! **** WARNING!*****" >&2
	echo "**                                                       **" >&2
	echo "** Your log indicates you didn't update the ACK details! **" >&2
	echo "** Please update the following before pushing upstream:  **" >&2
	git log $branch --not --remotes=*/master -- | grep "FirstName LastName" >&2
	echo "**                                                       **" >&2
	echo "***********************************************************" >&2
fi

exit 0
