svn强制commit写log

本文介绍如何通过TortoiseSVN或服务器端hook脚本强制要求用户在提交更改时输入日志消息。对于TortoiseSVN用户,可以通过设置项目属性实现;而对于所有Subversion客户端,则可以在服务器端安装预提交hook脚本来阻止没有日志消息的提交。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://tortoisesvn.net/docs/nightly/TortoiseSVN_en/tsvn-howto-minlogmsgsize.html

Force users to enter a log message

There are two ways to prevent users from committing with an empty log message. One is specific to TortoiseSVN, the other works for all Subversion clients, but requires access to the server directly.

Hook-script on the server

If you have direct access to the repository server, you can install a pre-commit hook script which rejects all commits with an empty or too short log message.

In the repository folder on the server, there's a sub-folder hooks which contains some example hook scripts you can use. The file pre-commit.tmpl contains a sample script which will reject commits if no log message is supplied, or the message is too short. The file also contains comments on how to install/use this script. Just follow the instructions in that file.

This method is the recommended way if your users also use other Subversion clients than TortoiseSVN. The drawback is that the commit is rejected by the server and therefore users will get an error message. The client can't know before the commit that it will be rejected. If you want to make TortoiseSVN have the OK button disabled until the log message is long enough then please use the method described below.

Project properties

TortoiseSVN uses properties to control some of its features. One of those properties is the tsvn:logminsize property.

If you set that property on a folder, then TortoiseSVN will disable the OK button in all commit dialogs until the user has entered a log message with at least the length specified in the property.

For detailed information on those project properties, please refer to the section called “Project Settings”.

 

具体操作

# On a Windows system, you should name the hook program
# 'pre-commit.bat' or 'pre-commit.exe',
# but the basic idea is the same.

需要注意的是, pre-commit.tmpl仅存在于具体的svn的repository中,并不存在于visual svn server的安装目录下。

直接使用everything,搜索pre-commit。然后按照文件内的说明,重命名为bat文件。结果发现默认的不能用

找到如下的脚本,直接将内容复制,然后覆盖原来的内容

 https://stackoverflow.com/questions/1928023/how-can-i-prevent-subversion-commits-without-comments

You can use a hook (put it into <repository>/hooks and name it pre-commit.bat (Windows)):

@echo off
::
:: Stops commits that have empty log messages.
::

setlocal

rem Subversion sends through the path to the repository and transaction id
set REPOS=%1
set TXN=%2

rem check for an empty log message
svnlook log %REPOS% -t %TXN% | findstr . > nul
if %errorlevel% gtr 0 (goto err) else exit 0

:err
echo. 1>&2
echo Your commit has been blocked because you didn't give any log message 1>&2
echo Please write a log message describing the purpose of your changes and 1>&2
echo then try committing again. -- Thank you 1>&2
exit 1

src: http://www.anujgakhar.com/2008/02/14/how-to-force-comments-on-svn-commit/

 

遇到问题'svnlook' is not recognized as an internal or external command,

https://serverfault.com/questions/165663/svnlook-is-not-recognized-as-an-internal-or-external-command-visualsvn-server

1.把这个目录配置到环境变量

C:\Program Files (x86)\VisualSVN Server\bin

2.然后重启VisualSvnServer这个windows service

 

如果svn的repository太多的话,可以写一个脚本,来自动复制pre-commit.bat

http://kockerbeck.blogspot.com/2010/08/require-comment-message-on-all-svn.html

@ECHO OFF
:: ------ SVN Deploy Hooks ------
:: ----- by Mark Kockerbeck  ----

:: ------ Configuration ---------
SET HookDirectory=C:\CommonHooks
SET RepositoryDirectory=C:\Repositories
:: ------ /Configuration --------

pushd %HookDirectory%
for /r %%i in (*) do (
 for /D %%j in (%RepositoryDirectory%\*) do (
  echo Copying %%i to %%j\hooks\
  copy %%i %%j\hooks\
 )
)
popd

 

转载于:https://www.cnblogs.com/chucklu/p/10609003.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值