【问题标题】:svn pre-commit hook is not getting executedsvn pre-commit 钩子没有被执行
【发布时间】:2015-08-03 18:14:06
【问题描述】:

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

我的 svn 存储库托管在此路径 /svn/development/ 中的 linux 盒子中 我修改了 /svn/development/hooks/pre-commit.sh 文件如下

  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

尝试从托管我的 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. 

有人能告诉我我缺少什么吗?

【问题讨论】:

    标签: svn pre-commit-hook


    【解决方案1】:

    好的,我想出了问题所在,但我从没想过会是这样。我的脚本被命名为 pre-comit.sh 但看起来它根本不应该有任何扩展名。我将它重命名为 pre-commit,它工作得很好。我尝试的选项 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="$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
    

    【讨论】:

      【解决方案2】:

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

      【讨论】:

      • 谢谢。我会试试的。但是,在调试时,我注释掉了整个脚本,并试图只触摸 /tmp 中的一个文件。理想情况下,当我执行 svn 提交时,这应该在 /tmp 中创建一个文件,对吗?它根本不这样做。所以我怀疑这个脚本是否被触发了。我现在将其更改为 if [ $SVNLOOKOK -eq 0 ];那么
      猜你喜欢
      • 1970-01-01
      • 2015-03-30
      • 1970-01-01
      • 2019-11-26
      • 2010-09-07
      • 2021-03-19
      • 1970-01-01
      • 2017-05-15
      • 2014-02-15
      相关资源
      最近更新 更多