I am assuming its a bare repository on the remote server. If it is, then 
 1) traverse to that repository directory. For example , cd my_repo.git
 2) then cd to hooks directory, For eg, cd hooks
 3) You need to put the logic in "update" hook. If it doesn't exist, create 
update file. I have all my hooks in bash.
 4) Put the logic in update hook and make sure you have set the execute 
permission on this hook.

You can find an excerpt of my hook that does exactly the same what you are 
looking for except that We use JIRA as the bug tracking tool.


*#!/bin/sh*

*# lock the myfeature branch for pushing*

*refname="$1"*

*oldrev="$2"*

*newrev="$3"*


*regex="^\s*IDB-[0-9]{4,5}\s.*"*

*mergeRegex="^\s*Merge branch\s.*"*

*# enforced custom commit message format*

*function check_message_format {*

*     #echo "oldrev is ${oldrev}"*

*     #echo "newrev is ${newrev}"*

*     missed_revs=$(echo $(git rev-list $oldrev..$newrev) | tr '\n' ' ')*

*     #echo "I have received the following commits => ${missed_revs}"*

*     for rev in ${missed_revs}*

*     do*

*       message=$(git cat-file commit ${rev} | sed '1,/^$/d')*

*       # message=`echo $(git cat-file commit ${rev}) | sed '1,/^$/d' `*

*       #echo "Received commit $rev with message ${message}"*

*       if [[ "${message}" =~ ${regex} ]]*

*       then*

*         echo "[PUSH SUCCEEDED!] Push successful for the commit ${rev}."*

*       else*

*          if [[ "${message}" =~ ${mergeRegex} ]]*

*          then*

*            echo 
"###############################################################"*

*            echo "[PUSH SUCCEEDED!] This is a merge commit.So I will let 
the push go through."*

*            echo 
"###############################################################"*

*          else*

*             echo 
"###############################################################"*

*             echo "[PUSH FAILED!] Please mention the JIRA bug number for 
the commit ${rev}."*

*             echo 
"###############################################################"*

*             exit 1*

*         fi*

*       fi*

*     done*

*}*

*check_message_format*
Please not that this is a working code and I have allowed merge commits to 
be allowed to check in. If you don't want that, remove it accordingly. 

On Monday, October 14, 2013 6:20:29 PM UTC+5:30, Ling wrote:
>
> Hello,
>  
> We are going to integrate the Git with VersionOne and also trying to 
> create some hooks that prevent when developers trying to commit/push the 
> changes into the remote repositories, for example: when developer trying to 
> commit/push the new changes from the local repository into the remote 
> repository, it require to enter the VersionOne defect#, and it will check 
> if it match this V1 defect#, or this V1 defect# is in correct state... then 
> it can be push into the remote repo, otherwise, it fire the hooks and 
> reject this commit/push.
>  
> So we are trying to get some ideas on how we can get this hooks create? 
>  
> Thanks
> Ling
>

-- 
You received this message because you are subscribed to the Google Groups "Git 
for human beings" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to git-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to