2011-08-12 09:51:28 +02:00
#!/bin/sh -e
2014-06-25 21:22:49 -07:00
# Since we run with '#!/bin/sh -e'
# '$? != 0' will force an exit,
# i.e. where we are interested in the result of a command,
# we have to run the command in an if-statement.
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
{
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 .;
}
2014-06-25 21:22:49 -07:00
check_patches_for_coding_style( )
{
git fetch origin;
check_patch_script = ./extras/checkpatch.pl
if [ ! -e ./extras/checkpatch.pl ] ; then
echo "checkpatch is not executable .. abort"
exit 1
fi
## Set this to known value once Jenkins URL changes
export JENKINS_URL = "review.gluster.org"
echo "Running coding guidelines check ..."
head = $( git rev-parse --abbrev-ref HEAD)
# Kludge: "1>&2 && echo $? || echo $?" is to get around
# "-e" from script invocation
RES = $( git format-patch --stdout origin/${ branch } ..${ head } \
| ${ check_patch_script } --terse - 1>& 2 && echo $? || echo $? )
if [ " $RES " -eq 1 ] ; then
echo "Errors caught, get details by:"
echo " git format-patch --stdout origin/ ${ branch } .. ${ head } \\ "
echo " | ./extras/checkpatch.pl --jenkins-url ${ JENKINS_URL } - "
echo "and correct errors"
exit 1
elif [ " $RES " -eq 2 ] ; then
echo "Warnings caught, get details by:"
echo " git format-patch --stdout origin/ ${ branch } .. ${ head } \\ "
echo " | ./extras/checkpatch.pl --jenkins-url ${ JENKINS_URL } - "
echo -n "Do you want to continue anyway [no/yes]: "
read yesno
if [ " ${ yesno } " != "yes" ] ; then
echo "Aborting..."
exit 1
fi
fi
}
2011-07-18 16:06:59 +05:30
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
2014-06-25 21:22:49 -07:00
check_patches_for_coding_style;
2011-07-18 16:06:59 +05:30
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 " $@ "