SVN 中的 pre-revprop-change 挂钩是什么?如何创建它?
我想在存储库浏览器中编辑日志注释,并收到一条错误消息,指出存储库不存在 pre-revprop-change 挂钩。 除了有一个可怕的名字之外,什么是 pre-revprop-change 挂钩,以及如何创建它?
I wanted to edit a log comment in the repository browser and received an error message that no pre-revprop-change hook exists for the repository. Besides having a scary name, what is a pre-revprop-change hook, and how do I create it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
对于 Windows,以下是示例批处理文件的链接,该文件仅允许更改日志消息(不允许更改其他属性):
http://ayria.livejournal.com/33438.html
基本上将下面的代码复制到文本文件中,并将其命名为
pre-revprop-change.bat
并将其保存在\hooks
存储库的子目录。For Windows, here's a link to an example batch file that only allows changes to the log message (not other properties):
http://ayria.livejournal.com/33438.html
Basically copy the code below into a text file and name it
pre-revprop-change.bat
and save it in the\hooks
subdirectory for your repository.基本上,它是在存储库上修改未版本控制的属性之前启动的脚本,以便您可以更精确地管理存储库上发生的情况。
SVN 发行版中有针对不同挂钩的模板,位于 /hooks 子目录中(*.tmpl,您必须根据您的操作系统对其进行编辑和重命名才能激活)。
Basically it's a script that is launched before unversioned property is modified on the repository, so that you can manage more precisely what's happening on your repository.
There are templates in the SVN distrib for different hooks, located in the /hooks subdirectory (*.tmpl that you have to edit and rename depending on your OS, to activate).
要让 Linux 允许编辑日志注释,
hooks
目录中找到文件pre-revprop-change.tmpl
,pre-revprop-change
www-data
)已编辑:(谢谢到 lindes)
0
。For Linux to allow the edition of a log comment,
pre-revprop-change.tmpl
in thehooks
directory of your repositorypre-revprop-change
www-data
)Edited: (thanks to lindes)
0
for the kind of edits, that you want to allow.这是堆栈溢出问题的链接,其中包含许多常见的钩子 Subversion 钩子的常见类型,包括此处交叉发布的 Windows 的
pre-revprop-change
挂钩的原始来源。您应该参考那里,因为它们可能会随着时间的推移而得到改进。
Here is the link to the stack overflow question with many common hooks Common Types of Subversion Hooks, including the original source of the
pre-revprop-change
hook for Windows cross-posted here.You should refer there as they may get improved over time.
谢谢#patmortech
,我添加了你的代码,“只有同一个用户才能更改他的代码”。
Thanks #patmortech
And I added your code which "only the same user can change his code".
如果您设法破译它,钩子脚本的名称并不那么可怕:它是预修订属性更改钩子。 简而言之,
的目的pre-revprop-change
钩子脚本用于控制未版本化(修订版)属性的更改并发送通知(例如,当修订版属性更改时发送电子邮件)。Subversion 中有两种类型的属性:
svn:log
和svn:date
)。版本化属性具有历史记录,并且可以由对存储库具有读/写访问权限的普通用户进行操作。 另一方面,未版本化的属性没有任何历史记录,主要用于维护目的。 例如,如果您提交修订,它会立即获取包含提交的 UTC 时间的
svn:date
、包含您的用户名的svn:author
和svn:log 与您的提交日志消息(如果您指定了任何消息)。
正如我已经指出的,
pre-revprop-change
挂钩脚本的目的是控制修订属性的更改。 您不希望有权访问存储库的每个人都能够修改所有修订版属性,因此默认情况下禁止更改修订版属性。 要允许用户更改属性,您必须创建pre-revprop-change
挂钩。最简单的钩子只能包含一行:
exit 0
。 它将允许任何经过身份验证的用户更改任何修订属性,并且不应在真实环境中使用。 在 Windows 上,您可以使用批处理脚本或基于 PowerShell 的脚本在pre-revprop-change
挂钩中实现一些逻辑。此 PowerShell 脚本仅允许更改 svn:log 属性并拒绝空日志消息。
此批处理脚本仅允许“svnmgr”用户更改修订版本属性:
The name of the hook script is not so scary if you manage decipher it: it's pre revision property change hook. In short, the purpose of
pre-revprop-change
hook script is to control changes of unversioned (revision) properties and to send notifications (e.g. to send an email when revision property is changed).There are 2 types of properties in Subversion:
svn:needs-lock
andsvn:mime-type
) that can be set on files and directories,svn:log
andsvn:date
) that are set on repository revisions.Versioned properties have history and can be manipulated by ordinary users who have Read / Write access to a repository. On the other hand, unversioned properties do not have any history and serve mostly maintenance purpose. For example, if you commit a revision it immediately gets
svn:date
with UTC time of your commit,svn:author
with your username andsvn:log
with your commit log message (if you specified any).As I already specified, the purpose of
pre-revprop-change
hook script is to control changes of revision properties. You don't want everyone who has access to a repository to be able to modify all revision properties, so changing revision properties is forbidden by default. To allow users to change properties, you have to createpre-revprop-change
hook.The simplest hook can contain just one line:
exit 0
. It will allow any authenticated user to change any revision property and it should not be used in real environment. On Windows, you can use batch script or PowerShell-based script to implement some logic withinpre-revprop-change
hook.This PowerShell script allows to change
svn:log
property only and denies empty log messages.This batch script allows only "svnmgr" user to change revision properties:
如果您想保存对日志消息的更改,请使用 @patmortech 上面答案中的批处理脚本 (https://stackoverflow.com/ a/468475),
谁从 https://stackoverflow.com/a/68850 复制了脚本,
并在
if "%bIsEmpty%" == "true" goto ERROR_EMPTY
和goto :eofbefore
之间添加这些行:它将创建一个文本文件
log-change-在服务器上的 repo 文件夹中保存history.txt
并附加每个日志更改通知。If you want to save the changes on the log messages, use the batch script from the answer above from @patmortech (https://stackoverflow.com/a/468475),
who copied the script from https://stackoverflow.com/a/68850,
and add these lines between
if "%bIsEmpty%" == "true" goto ERROR_EMPTY
andgoto :eofbefore
:It will create a text file
log-change-history.txt
in the repo folder on the server and append each log change notification.对于电脑用户:
在 Windows Server 机器上使用时,.bat 扩展名对我不起作用。 我按照 Django Reinhardt 的建议使用 VisualSvn,它创建了一个带有 .cmd 扩展名的钩子。
For PC users:
The .bat extension did not work for me when used on Windows Server maching. I used VisualSvn as Django Reinhardt suggested, and it created a hook with a .cmd extension.
(这个解决方案肯定有缺点,因为没有检查/禁止任何内容。但对于我的情况 - 只有我正在使用的本地存储库 - 它似乎有效。)
(This solution surely has drawbacks, as nothing is checked/prohibited. But for my case - a local repo that only I am using - it seems to work.)
这对我来说在 Windows Server 上是最简单的:
在 VisualSVN 中右键单击您的存储库,然后选择属性...,然后选择挂钩选项卡。
选择预修订属性更改挂钩,单击编辑。
我需要能够更改作者 - 这经常发生在多人使用的远程计算机上,我们错误地使用其他人存储的凭据进行签入。
以下是要粘贴的修改后的社区 wiki 脚本:
This was the easiest for me on a Windows Server:
In VisualSVN right-click your repository, then select Properties... and then the Hooks tab.
Select Pre-revision property change hook, click Edit.
I needed to be able to change the Author - it often happens on remote computers used by multiple people, that by mistake we check-in using someone else's stored credentials.
Here is the modified community wiki script to paste:
正如 Alois Helmer 之前回答的那样,您需要在要允许修订注释编辑的 SVN 存储库内的
hooks
目录中找到文件pre-revprop-change.tmpl
。对我来说,创建一个带有
pre-revprop-change name
的副本就足够了,尽管您可以编辑它以仅允许某些用户修改评论或您有的其他一些需求。然后,您必须使用
chmod 755 pre-revprop-change
授予常规读取和执行权限,但是常规执行权限是不够的。 您需要在 SELinux 中为该脚本授予 Apache/HTTPD 执行权限,如下所示。
如果不这样做,您将收到以下错误,该错误提供的信息很少,并且很难与 SELinux 配置相关联。
As Alois Helmer answered before, you need to locate the file
pre-revprop-change.tmpl
in thehooks
directory inside the SVN repository you want to allow revision comments edition.For me, to create a copy with
pre-revprop-change name
was sufficient, though you could edit it to allow only certain users to modify the comments or some other needs you have.And then you must grant regular read and execution permissions using
chmod 755 pre-revprop-change
But regular execution permissions are not enough. You need to give Apache/HTTPD execution grants in SELinux for that script like this.
If you not, you'll get the following error that gives little information and it's hard to relate to a SELinux conf.