天天看點

SVN送出時強制使用者寫日志

在使用SVN進行項目管理的過程中,為了對各版本送出狀況進行了解,我們需要在SVN送出過程中強制使用者輸入一定的日志。

下面介紹一下如何來限制使用者SVN送出時必須輸入日志。

步驟:

1、進入SVN倉庫的hooks目錄,把pre-commit.tmpl檔案重命名為pre-commit

2、修改pre-commit檔案

修改前:

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           

複制

修改後:

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行進行注釋:

$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           

複制

然後添加以下幾行指令:

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

chmod 755 pre-commit           

複制

修改完後,測試了一下,在沒有輸入日志時送出SVN,提示錯誤

Commit failed (details follow): Commit blocked by pre-commit hook (exit code 1) with output: 注釋不能為空,且字數必須大于10個字元           

複制

輸入一定的字數後送出成功!

這裡的錯誤提示可以修改echo 裡面輸出的内容:

echo -e "\nLog message cann't be empty! you must input more than 10 chars as comment!。" 1>&2           

複制