svn 预提交挂钩没有被执行

svn pre-commit hook is not getting executed

我知道这个问题在这里被问了很多次,但我的问题是我尝试了这里列出的所有解决方案,但在执行预提交挂钩时仍然遇到问题。

我的 svn 存储库位于此路径 /svn/development/ 的 linux 框中 我修改了 /svn/development/hooks/pre-commit.sh 文件如下

  REPOS=""
  TXN=""
  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

尝试从托管我的 svn 存储库的盒子本地提交,也尝试使用 Tortoise svn 远程提交。我能够提交空消息。

    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. 

有人能告诉我我错过了什么吗?

您错误地将变量与数字进行了比较。你这样做的方式是进行字符串比较。参见https://superuser.com/q/688882/233630;有几种方法可以正确执行此操作,包括将“=”替换为“-eq”。

好的,我想出了问题所在,但我从没想过会是这样。我的脚本被命名为 pre-comit.sh 但看起来它根本不应该有任何扩展名。我将其重命名为预提交并且它工作得很好。我尝试的选项 1 和 2 也是强制性的,脚本才能正常工作。我的新脚本检查空消息并在 JIRA 中检查有效的问题编号和消息。我已经给出了下面的脚本。

参考:SVN hooks not working

另请阅读此处的实施存储库挂钩 http://svnbook.red-bean.com/en/1.8/svn.reposadmin.create.html#svn.reposadmin.create.hooks

 #!/bin/bash
 REPOS=""
 TXN=""

 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