2011-08-12 11:51:28 +04:00
#!/bin/sh -e
2011-07-18 14:36:59 +04:00
branch = "master" ;
2011-08-12 11:51:28 +04:00
set_hooks_commit_msg( )
2011-07-18 14:36:59 +04:00
{
f = ".git/hooks/commit-msg" ;
u = "http://review.gluster.com/tools/hooks/commit-msg" ;
if [ -x " $f " ] ; then
return ;
fi
curl -o $f $u || wget -O $f $u ;
chmod +x .git/hooks/commit-msg;
}
2011-08-12 11:51:28 +04:00
is_num( )
2011-07-18 14:36:59 +04:00
{
local num;
num = " $1 " ;
[ -z " $( echo $num | sed -e 's/[0-9]//g' ) " ]
}
2011-08-12 11:51:28 +04:00
rebase_changes( )
2011-07-18 14:36:59 +04:00
{
2011-07-23 07:50:53 +04:00
git fetch;
2011-07-18 14:36:59 +04:00
2011-07-23 07:50:53 +04:00
GIT_EDITOR = $0 git rebase -i origin/$branch ;
2011-07-18 14:36:59 +04:00
}
2011-08-12 11:51:28 +04:00
editor_mode( )
2011-07-18 14:36:59 +04:00
{
if [ $( basename " $1 " ) = "git-rebase-todo" ] ; then
2011-08-12 08:43:07 +04:00
sed 's/^pick /reword /g' " $1 " > $1 .new && mv $1 .new $1 ;
2011-07-18 14:36:59 +04:00
return ;
fi
if [ $( basename " $1 " ) = "COMMIT_EDITMSG" ] ; then
if grep -qi '^BUG: ' $1 ; then
return ;
fi
while true; do
echo Commit: " \" $( head -n 1 $1 ) \" "
echo -n "Enter Bug ID: "
read bug
if [ -z " $bug " ] ; then
return ;
fi
if ! is_num " $bug " ; then
echo " Invalid Bug ID ( $bug )!!! " ;
continue ;
fi
2011-08-12 12:26:47 +04:00
sed " s/^\(Change-Id: .*\) $/\1\nBUG: $bug /g " $1 > $1 .new && \
2011-08-12 11:51:28 +04:00
mv $1 .new $1 ;
2011-07-18 14:36:59 +04:00
return ;
done
fi
cat <<EOF
$0 - editor_mode called on unrecognized file $1 with content:
$( cat $1 )
EOF
return 1;
}
2011-08-12 11:51:28 +04:00
assert_diverge( )
2011-07-18 14:36:59 +04:00
{
git diff origin/$branch ..HEAD | grep -q .;
}
2011-08-12 11:51:28 +04:00
main( )
2011-07-18 14:36:59 +04:00
{
if [ -e " $1 " ] ; then
editor_mode " $@ " ;
return ;
fi
set_hooks_commit_msg;
rebase_changes;
assert_diverge;
bug = $( git show --format= '%b' | grep -i '^BUG: ' | awk '{print $2}' ) ;
2011-07-23 08:03:18 +04:00
if [ " $DRY_RUN " = 1 ] ; then
drier = 'echo -e Please use the following command to send your commits to review:\n\n'
else
drier =
fi
2011-07-18 14:36:59 +04:00
if [ -z " $bug " ] ; then
2011-07-23 08:03:18 +04:00
$drier git push origin HEAD:refs/for/$branch /rfc;
2011-07-18 14:36:59 +04:00
else
2011-07-23 08:03:18 +04:00
$drier git push origin HEAD:refs/for/$branch /bug-$bug ;
2011-07-18 14:36:59 +04:00
fi
}
main " $@ "