VisualSVN:允许修改svn提交日志(pre-revpro-change hook)
Posted 陌鉎こ城sHi
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VisualSVN:允许修改svn提交日志(pre-revpro-change hook)相关的知识,希望对你有一定的参考价值。
有时候需要对之前版本提交的错误的日志信息进行修改或者进行补充描述:
1、在windows 7( 64位 )下使用TortoiseSVN客户端,选中代码目录,点击右键,选择<显示日志>
在出来的日志列表对话框中,选择某个提交版本,再点击右键,选择<编辑日志信息>,如下图所示:
我们修改原来空白的日志信息
万恶报错信息出现了
这个时候怎么处理呢??难道SVN不爱我们了!!
由于缺省情况下为安全起见Subversion不允许开发人员修改已提交reversion的日志信息,这样会报错误,提示不能修改以及请SVN管理员安装pre revprop change hook。
visualSVN Server每个Repositories下都有一个hooks文件夹,如下图,已经有一堆tmpl文件,这些文件其实就是linux 的shell脚本模板。
我们先打开pre-revprop-change.tmpl来看看,pre-revpro-change.tmpl就是linux版的pre-revprop-change hook
的模板,在linux下赋予执行权限就可以使用。
1 #!/bin/sh 2 3 # PRE-REVPROP-CHANGE HOOK 4 # 5 # The pre-revprop-change hook is invoked before a revision property 6 # is added, modified or deleted. Subversion runs this hook by invoking 7 # a program (script, executable, binary, etc.) named \'pre-revprop-change\' 8 # (for which this file is a template), with the following ordered 9 # arguments: 10 # 11 # [1] REPOS-PATH (the path to this repository) 12 # [2] REV (the revision being tweaked) 13 # [3] USER (the username of the person tweaking the property) 14 # [4] PROPNAME (the property being set on the revision) 15 # [5] ACTION (the property is being \'A\'dded, \'M\'odified, or \'D\'eleted) 16 # 17 # [STDIN] PROPVAL ** the new property value is passed via STDIN. 18 # 19 # If the hook program exits with success, the propchange happens; but 20 # if it exits with failure (non-zero), the propchange doesn\'t happen. 21 # The hook program can use the \'svnlook\' utility to examine the 22 # existing value of the revision property. 23 # 24 # WARNING: unlike other hooks, this hook MUST exist for revision 25 # properties to be changed. If the hook does not exist, Subversion 26 # will behave as if the hook were present, but failed. The reason 27 # for this is that revision properties are UNVERSIONED, meaning that 28 # a successful propchange is destructive; the old value is gone 29 # forever. We recommend the hook back up the old value somewhere. 30 # 31 # On a Unix system, the normal procedure is to have \'pre-revprop-change\' 32 # invoke other programs to do the real work, though it may do the 33 # work itself too. 34 # 35 # Note that \'pre-revprop-change\' must be executable by the user(s) who will 36 # invoke it (typically the user httpd runs as), and that user must 37 # have filesystem-level permission to access the repository. 38 # 39 # On a Windows system, you should name the hook program 40 # \'pre-revprop-change.bat\' or \'pre-revprop-change.exe\', 41 # but the basic idea is the same. 42 # 43 # The hook program typically does not inherit the environment of 44 # its parent process. For example, a common problem is for the 45 # PATH environment variable to not be set to its usual value, so 46 # that subprograms fail to launch unless invoked via absolute path. 47 # If you\'re having unexpected problems with a hook program, the 48 # culprit may be unusual (or missing) environment variables. 49 # 50 # Here is an example hook script, for a Unix /bin/sh interpreter. 51 # For more examples and pre-written hooks, see those in 52 # the Subversion repository at 53 # http://svn.apache.org/repos/asf/subversion/trunk/tools/hook-scripts/ and 54 # http://svn.apache.org/repos/asf/subversion/trunk/contrib/hook-scripts/ 55 56 57 REPOS="$1" 58 REV="$2" 59 USER="$3" 60 PROPNAME="$4" 61 ACTION="$5" 62 63 if [ "$ACTION" = "M" -a "$PROPNAME" = "svn:log" ]; then exit 0; fi 64 65 echo "Changing revision properties other than svn:log is prohibited" >&2 66 exit 1
VisualSVN server运行在Windows平台,所以这些hook脚本是不可能能执行的。但只要照着这些hook模板代码的逻辑用bat脚本重写这些脚本,就可以实现windows下的hook.
pre-revprop-change.bat代码如下
1 setlocal 2 set REPOS=%1 3 set REV=%2 4 set USER=%3 5 set PROPNAME=%4 6 set ACTION=%5 7 if not "%ACTION%"=="M" goto refuse 8 if not "%PROPNAME%"=="svn:log" goto refuse 9 goto OK 10 :refuse 11 echo Cann\'t set %PROPNAME%/%ACTION%, only svn:log is allowed 1>&2 12 endlocal 13 exit 1 14 :OK 15 endlocal 16 exit 0
好了现在重新开始测试
难道SVN不爱我们了吗,不是,原来是我们不懂SVN的心
小技巧
如果不想在中添加bat文件该怎么弄
将之前的 pre-revprop-change.bat中内容直接复制到这个里
好了我们还是测试一下吧
以上是关于VisualSVN:允许修改svn提交日志(pre-revpro-change hook)的主要内容,如果未能解决你的问题,请参考以下文章
允许用户修改Subversion日志的钩子脚本 (linux)
VisualSVN Server与TortoiseSVN搭建SVN版本控制系统