在使用SVN进行项目管理的过程中,为了对各版本提交状况进行了解,我们需要在SVN提交过程中强制用户输入一定的日志。
下面介绍一下如何来限制用户SVN提交时必须输入日志。
步骤:
1、进入SVN仓库的hooks目录,把pre-commit.tmpl文件重命名为pre-commit
2、修改pre-commit文件
修改前:
代码语言:javascript复制REPOS="$1" TXN="$2" # Make sure that the log message contains some text. SVNLOOK=/usr/bin/svnlook $SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null || exit 1 # Check that the author of this commit has the rights to perform # the commit on the files and directories being modified. commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1 # All checks passed, so allow the commit. exit 0
修改后:
代码语言:javascript复制REPOS="$1" TXN="$2" # Make sure that the log message contains some text. SVNLOOK=/usr/bin/svnlook #$SVNLOOK log -t "$TXN" "$REPOS" | # grep "[a-zA-Z0-9]" > /dev/null || exit 1 # Check that the author of this commit has the rights to perform # the commit on the files and directories being modified. #commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1 LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c` if [ "$LOGMSG" -lt 10 ];#要求注释不能少于10个字符 then echo -e "n注释不能为空,且字数必须大于10个字符." 1>&2 exit 1 fi # All checks passed, so allow the commit. exit 0
其实就是把源文件中的以下3行进行注释:
代码语言:javascript复制$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" > /dev/null || exit 1 commit-access-control.pl "$REPOS" "$TXN" commit-access-control.cfg || exit 1
然后添加以下几行命令:
代码语言:javascript复制LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c` if [ "$LOGMSG" -lt 10 ];#要求注释不能少于10个字符 then echo -e "nLog message cann't be empty! you must input more than 10 chars as comment!." 1>&2 exit 1 fi
3、把pre-commit文件修改为755
代码语言:javascript复制chmod 755 pre-commit
修改完后,测试了一下,在没有输入日志时提交SVN,提示错误
代码语言:javascript复制Commit failed (details follow): Commit blocked by pre-commit hook (exit code 1) with output: 注释不能为空,且字数必须大于10个字符
输入一定的字数后提交成功!
这里的错误提示可以修改echo 里面输出的内容:
代码语言:javascript复制echo -e "nLog message cann't be empty! you must input more than 10 chars as comment!。" 1>&2