如何設定SVN版本控制工具必須寫注釋才能提交:
當我們用tortoisesvn等SVN工具提交代碼時,有很多人不喜歡寫注釋的而直接提交,這樣一來代碼版本多了,根本搞不清,哪個版本改了什麼東西?所以如果加一些注釋的話,我們看起來,也方便很多。所以在提交的時候,我會強制要求,寫注釋。如果對svn的安裝配置不怎麼瞭解,請參考:linux svn安裝和配置,不結合apache
1, cd /home/administrator/www/svn_test svn_test是一個代碼倉庫
2,mv ./hooks/pre-commit.tmpl ./hooks/pre-commit 將代碼倉庫根目錄下,hooks檔案夾中的pre-commit.tmpl檔案重新命名為pre-commit
3,vim ./hooks/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
# Exit on all errors.
set -e
# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
"$REPOS"/hooks/commit-access-control.pl "$REPOS" $TXN /
"$REPOS"/hooks/commit-access-control.cfg
# 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
LOGMSG=`$SVNLOOK log -t $TXN $REPOS | wc -m` //定義個變數,注意這裡不是單引號
#$SVNLOOK log -t "$TXN" "$REPOS" | / //把這一行和下面的一行注釋掉
# grep "[a-zA-Z0-9]" > /dev/null || exit 1
echo $LOGMSG > /home/administrator/www/aaa.txt //為了測試變數用的,查看$LOGMSG有沒有值,最後要注釋掉
if [ "$LOGMSG" -lt 48 ] //這裡為什麼是48呢,一個漢字對應16個字元
then
echo "/n至少輸入4個漢字" >&2 //必須填四個漢字
exit 1
fi
# Exit on all errors.
#set -e
# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
#"$REPOS"/hooks/commit-access-control.pl "$REPOS" $TXN / //把這一行和下面的一行注釋掉。
# "$REPOS"/hooks/commit-access-control.cfg
# All checks passed, so allow the commit.
exit 0
4,儲存後,我們要給pre-commit這個檔案,加可執行許可權chmod +x pre-commit,有一點在說一下就是$SVNLOOK 前面的不是單引號,具體shell文法,請參考shell手冊