svn 强制提交日志log
? svn ? ? shell ?    2019-10-12 10:00:26    1751    1    0
gua_l   ? svn ? ? shell ?

svn 强制提交日志

分析:

检查时间:提交前

效果:日志符合要求成功提交,日志不符合要求给出提示,并中断提交。

 

适用钩子脚本:svn -> hooks -> pre-commit (commit 前触发执行的脚本),当svn 有commit 请求时,会触发执行pre-commit(shell脚本),当这个脚本以非0退出时,中断commit , 当脚本正常退出时,允许commit.

 

进入版本库配置目录hooks ,可见模板 pre-commit.tmpl ,复制为pre-commit 。

root@tclserver:/var/svn/svn_dir/Auto_script/hooks# ll
-rwxr-xr-x 1 root root 3350 Apr 6 2017 pre-commit*
-rwxr-xr-x 1 root root 3510 Feb 6 2017 pre-commit.tmpl*


 pre-commit.tmpl 原模板的内容分析

# PRE-COMMIT HOOK
#
# The pre-commit hook is invoked before a Subversion txn is
# committed.  Subversion runs this hook by invoking a program
# (script, executable, binary, etc.) named 'pre-commit' (for which
# this file is a template), with the following ordered arguments:
#
#   [1] REPOS-PATH   (the path to this repository)
#   [2] TXN-NAME     (the name of the txn about to be committed)
#   ........
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​

其中有一个重要命令$SVNLOOK log -t "$TXN" "$REPOS" 

# [1] REPOS-PATH (the path to this repository)
# [2] TXN-NAME (the name of the txn about to be committed)

查看svnlook log -t 的用法为

log: usage: svnlook log REPOS_PATH

Print the log message.

Valid options:
-r [--revision] ARG : specify revision number ARG
-t [--transaction] ARG : specify transaction name ARG

即打印某个库路径下某个提交操作的日志 。

 


对新建的pre-commit 进行编辑,实现提交前检查日志长度,小于15字节,给出提示,提交中断,大于15字节,提交成功。

REPOS="$1"
TXN="$2"
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c)
if [ "$LOGMSG" -lt 15 ]
then
echo -e "\nLog message cann't be empty! you must indicate the content of the bug,more than 15 bytes" 1>&2
exit 1
fi
exit 0​

 

编辑后保存,使用空日志提交一个文件,验证成功

 


 

过程的小坑

1.Hooks pre-commit 失败

报svn: E165001: Commit blocked by pre-commit hook (exit code 255) with no output
任何提交都无成功,报错,除非把pre-commit文件拿走。想到可能是格式问题,pre-coommit是从wins写好拷进去的,执行了dos2uinx仍不行,于是老实linux目录下的模板pre-commit.temp重命名并重新编辑。就可以顺利提交。

2.Hooks pre-commit 无效

但是提交后发现钩子脚本无效,即使空日志也能成功提交。
LOGMSG='$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c'
if ["$LOGMSG" -lt 5 ];
调试后发现两个错误
LOGMSG=$($SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc –c)
If [ "$LOGMSG" -lt 5 ];
单引号改成括号并加$,或者改成反引号: $(CMD) , `CMD`
If 后的方括号用空格与内容隔开。
重新提交,脚本生效

 

 

Pre: Ubuntu - 64位系统缺失32位共享库

Next: Git 的review 方式 : gitlab 的 Merge request 和 gerrit

1751
Sign in to leave a comment.
No Leanote account? Sign up now.
0 comments
Table of content