2011-08-12 09:51:28 +02:00
#!/bin/sh -e
2011-07-18 16:06:59 +05:30
branch = "master" ;
2011-08-12 09:51:28 +02:00
set_hooks_commit_msg( )
2011-07-18 16:06:59 +05:30
{
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;
2012-08-07 00:14:43 -07:00
# Let the 'Change-Id: ' header get assigned on first run of rfc.sh
GIT_EDITOR = true git commit --amend;
2011-07-18 16:06:59 +05:30
}
2011-08-12 09:51:28 +02:00
is_num( )
2011-07-18 16:06:59 +05:30
{
local num;
num = " $1 " ;
[ -z " $( echo $num | sed -e 's/[0-9]//g' ) " ]
}
2011-08-12 09:51:28 +02:00
rebase_changes( )
2011-07-18 16:06:59 +05:30
{
2012-04-16 17:53:06 +02:00
git fetch origin;
2011-07-18 16:06:59 +05:30
2011-07-23 05:50:53 +02:00
GIT_EDITOR = $0 git rebase -i origin/$branch ;
2011-07-18 16:06:59 +05:30
}
2011-08-12 09:51:28 +02:00
editor_mode( )
2011-07-18 16:06:59 +05:30
{
if [ $( basename " $1 " ) = "git-rebase-todo" ] ; then
2011-08-12 06:43:07 +02:00
sed 's/^pick /reword /g' " $1 " > $1 .new && mv $1 .new $1 ;
2011-07-18 16:06:59 +05:30
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:00:49 +02:00
sed " /^Change-Id:/{p; s/^.* $/BUG: $bug /;} " $1 > $1 .new && \
2011-08-12 09:51:28 +02:00
mv $1 .new $1 ;
2011-07-18 16:06:59 +05:30
return ;
done
fi
cat <<EOF
$0 - editor_mode called on unrecognized file $1 with content:
$( cat $1 )
EOF
return 1;
}
2011-08-12 09:51:28 +02:00
assert_diverge( )
2011-07-18 16:06:59 +05:30
{
git diff origin/$branch ..HEAD | grep -q .;
}
2011-08-12 09:51:28 +02:00
main( )
2011-07-18 16:06:59 +05:30
{
2013-08-14 16:11:40 -07:00
set_hooks_commit_msg;
2011-07-18 16:06:59 +05:30
if [ -e " $1 " ] ; then
editor_mode " $@ " ;
return ;
fi
rebase_changes;
assert_diverge;
bug = $( git show --format= '%b' | grep -i '^BUG: ' | awk '{print $2}' ) ;
2011-07-23 06:03:18 +02: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 16:06:59 +05:30
if [ -z " $bug " ] ; then
2011-07-23 06:03:18 +02:00
$drier git push origin HEAD:refs/for/$branch /rfc;
2011-07-18 16:06:59 +05:30
else
2011-07-23 06:03:18 +02:00
$drier git push origin HEAD:refs/for/$branch /bug-$bug ;
2011-07-18 16:06:59 +05:30
fi
}
main " $@ "