I have started using Gerrit 2.16 as code review tool and want to configure server side hooks to validate the git commit message when a change is committed/pushed to gerrit.
Tried using hooks by copying scripts to $GIT_DIR/hooks (scripts like ref-update, patchset-created, change-merged), gave permission on the gerrit server but nothing works.
commit-msg hook can be enabled on local repository by using command give in gerrit UI
example: git clone ssh://@:29418/Project1 && scp -p -P 29418 @:hooks/commit-msg /.git/hooks/
change_ID will be automatically generated if this hook is enabled.
This script commit-msg gets downloaded to local repository when above command is executed.
My question; can we find path of this script on the gerrit server, so that I can modify and enforce git commit message validation?
Or is there any other way to enable gerrit server side hooks?
#!/bin/bash
echo "Executing hook from Gerrit_DIR "
bold=$(tput bold)
normal=$(tput sgr0)
RED='\033[0;31m'
NC='\033[0m' # No Color
GIT_DIR="/opt/gerrit/site/git"
PROJECT=$2
REFNAME=$4
UPLOADER=$6
OLDREV=$8
NEWREV="${10}"
BASE="<baseDir>"
RepoDir="$GIT_DIR/$PROJECT.git"
echo $RepoDir
echo $PROJECT
echo $8
echo ${10}
# execute the project specific hook
if [ -f "$RepoDir/hooks/commit-received" ]
then
echo "Executing the project specific hook"
$RepoDir/hooks/commit-received $RepoDir ${10}
else
echo "There is no project specific hook"
fi