svn强制commit写log

时间:2023-03-09 04:34:13
svn强制commit写log

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://*.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