I am looking for a shell script (sh, not bash possibly) that would refuse any push to master which has any non-linear history.
I t
After much struggle on the sourceforge server here is what I got:
#!/bin/sh
# Author: Mathieu Malaterre
# This code is free software. It can be used and distributed under the
# same terms as git itself.
# http://stackoverflow.com/questions/5482887/how-to-avoid-merge-branch-master-of-ssh-gdcm-git-sourceforge-net-gitroot-gdc
read rev_old rev_new refname
ref_to_check="refs/heads/master"
if [ "$refname" = "$ref_to_check" ]
then
merge_bases=`git merge-base ${rev_old} ${rev_new}`
if [ "$merge_bases" != "$rev_old" ]
then
echo "Non fastward is disallowed"
exit 1
fi
# non-fast-forward case:
git rev-list --parents $merge_bases..$rev_new \
| while read x; do
set -- $x
if [ "$#" != "2" ]
then
echo "Multiple parents: $x";
exit 1
fi;
done
[ $? -ne 0 ] && exit 1
fi
exit 0