1
votes

I know this question is asked so many times here but my problem is i tried every solution that is listed out here and still having issues executing the pre-commit hook.

My svn repository is hosted in a linux box in this path /svn/development/ I modified the /svn/development/hooks/pre-commit.sh file as below

  REPOS="$1"
  TXN="$2"
  SVNLOOK=/usr/bin/svnlook
  SVNLOOKOK=1

 $SVNLOOK log -t "$TXN" "$REPOS" | \
 grep "[a-zA-Z0-9]" > /dev/null || SVNLOOKOK=0
 if [ $SVNLOOKOK -eq 0 ]; then
 echo -e "Empty log messages are not allowed. Make sure you provide a valid JIRA number and a meaningful log message." 1>&2 || exit 1
 fi
 exit 0

Tried to commit locally from the box where my svn repository is hosted and also remotely using Tortoise svn. I am able to commit with null message.

    1) Modified /etc/selinux/config -> SELINUX=disabled to enforcing and restarted apache
    2) Ran chcon -t httpd_exec_t pre-commit  
    3) Verified all the permissions. 

Could someone tell me what I am missing?

2

2 Answers

4
votes

OK I figured what the issue is and I never thought it would be the case. My script was named pre-comit.sh but looks like it shouldn't have any extension at all. I renamed it to pre-commit and it worked just fine. The option 1 and 2 that I tried is mandatory as well for the script to work. My new script checks for null message and checks in JIRA for a valid issue number followed by a message. I have given the script below.

Reference: SVN hooks not working

Also read the Implementing Repository Hooks from here http://svnbook.red-bean.com/en/1.8/svn.reposadmin.create.html#svn.reposadmin.create.hooks

 #!/bin/bash
 REPOS="$1"
 TXN="$2"

 SVNLOOK=/usr/bin/svnlook
 CURL=/usr/bin/curl
 JIRAURL=http://host/rest/api/2/issue
 # Make sure that the log message is not null
 LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS")
 if [ `echo ${LOGMSG} | grep "[a-zA-Z0-9]" | wc -c` -lt 8 ]
    then
       echo "Provide a meaningful comment when committing changes" >&2
       exit 1
 fi
 # check that log message starts with a JIRA issue number
 JIRAID=$(expr "${LOGMSG}" : '^\([A-Z]*-[0-9]*\)[: ].*')
 if [[ "$JIRAID" == "" ]]
    then
      echo "svn commit message should start with a valid JIRA id followed by a meaningful log message " >&2
      exit 1
 fi

 # check if JIRA issue exists
 JIRAISSUE=$(${CURL} ${JIRAURL}/${JIRAID})
 if [[ "${JIRAISSUE}" =~ "Issue Does Not Exist" ]]
    then
       echo "${JIRAID} is not a valid JIRA number." >&2
       echo "svn commit message should start with a valid JIRA id followed  by a meaningful log message" >&2
       exit 1
  fi
0
votes

You are comparing your variable to a number incorrectly. The way you are doing it is for string comparisons. See https://superuser.com/q/688882/233630; there are several ways to do it correctly, including replacing "=" with "-eq".