SVN 预提交挂钩,用于避免更改标签子目录
有没有人对如何添加避免更改标签子目录的预提交挂钩有明确的说明?
我已经在互联网上搜索了很多。 我找到了这个链接: SVN::Hooks::DenyChanges ,但我可以'似乎没有编译东西。
Is there anybody who has clear instructions on how to add a pre-commit hook that avoids changes to tags subdirectories?
I already searched the internet quite a bit. I found this link: SVN::Hooks::DenyChanges , but I can't seem to compile things.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
我没有足够的声誉来“评论”上面 Raim 的答案,但他的效果很好,除了一个例外,他的 grep 模式是错误的。
我只是使用下面的作为我的预提交钩子(我没有现有的钩子,在这种情况下你需要合并):
Raim 的 grep 模式的唯一问题是它只匹配“标签”,如果它是在你的仓库的“根”。 由于我的存储库中有几个项目,因此他编写的脚本允许在标签分支上提交。
另外,请务必按照指示进行 chmod +x ,否则您会认为它可以工作,因为提交失败了,但它失败了,因为它无法执行预提交挂钩,而不是因为挂钩起作用了。
这真的很棒,谢谢雷姆。 比所有其他建议更好、更轻,因为它没有依赖性!
I don't have enough reputation to "comment" on Raim's answer above, but his worked great, with one exception, his grep pattern is wrong.
I simply used the below as my pre-commit hook (I didn't have an existing one, you'd need to merge in that case):
The only problem with Raim's grep pattern is that it only matched "tags" if it was at the "root" of your repo. Since I have several projects in my repo, the script as he wrote it allowed commits on tag branches.
Also, be sure to chmod +x as indicated, otherwise you'll think it worked b/c the commit failed, but it failed b/c it couldn't exec the pre-commit hook, not because the hook worked.
This was really great, thanks Raim. Much better and lighter weight than all other suggestions as it has no dependencies!
下面是一个简短的 shell 脚本,用于防止在创建标签后提交标签:
将其保存在 Subversion 存储库的
hooks/pre-commit
中,并使用chmod +x
使其可执行>。Here is a short shell script to prevent committing to tags after they have been created:
Save this at
hooks/pre-commit
for your Subversion repository and make it executable withchmod +x
.这是我的 Windows 批处理文件预提交挂钩。 如果用户是管理员,则将跳过其他检查。 它检查提交消息是否为空,以及提交是否针对标签。 注意:findstr 是其他平台上 grep 的削弱替代品。
它检查提交是否针对标签的方式是,它首先检查 svnlook 更改是否包含“tags/”。 然后它会检查 svnlook Changed 是否与“^A.tags/[^/]/$”匹配,这意味着它将检查您是否在 Tags/ 下添加新文件夹。
允许用户创建新项目。 预提交挂钩允许用户创建文件夹 trunk/tags/ 和branches/。 用户不允许删除文件夹 trunk/tags/ 和branches/。 这适用于单个或多项目存储库。
Here is my windows batch file pre-commit hook. If the user is an administrator the other checks will be skipped. It checks if the commit message is empty, and if the commit is to a tag. Note: findstr is a nerfed alternative to grep on other platforms.
The way it checks if the commit is to a tag, it first checks if svnlook changed contains "tags/". It then checks if svnlook changed matches "^A.tags/[^/]/$", which means that it will check if you are adding a new folder under tags/.
Users are allowed to create new projects. The pre-commit hook allows a user to create the folders trunk/ tags/ and branches/. Users are not allowed to delete the folders trunk/ tags/ and branches/. This will work for a single or multi-project repository.
这个 anwser 已经过时了很多,但我发现了 svnlook 更改命令的 --copy-info 参数。
该命令的输出在第三列中添加了一个“+”,因此您知道它是一个副本。 您可以检查对标签目录的提交,并且只允许带有“+”的提交。
我在我的博客文章中添加了一些输出。
This anwser is a lot after date, but I discovered the --copy-info parameter for the svnlook changed command.
The output of this command adds a '+' in the third column, so you know it is a copy. You can check for commits to the tags directory, and only allow commits with a '+' present.
I've added some output in my blog post.
聚会已经很晚了,但是我写了一个 python 预提交挂钩,它基于 http://subversion.tigris.org/。
该脚本应该执行您想要的操作,但是它还检查日志消息是否存在,尽管这应该很容易从脚本中删除。
一些注意事项:
需求:
最后是代码:
Pretty late to the party, however I wrote a python pre-commit hook for work which is based off the log-police.py script on http://subversion.tigris.org/.
This script should do what you want, however it also checks that a log message exists, though that should be easy to remove from the script.
Some caveats:
Requirements:
Finally, the code:
以前写的脚本大多不完整,因为有几种情况没有涵盖。 这是我的脚本:
它可能看起来很复杂,但您必须确保您位于
/tags
中,并且如果/tags
不存在,则允许您创建它以及所有后续内容文件夹。 任何其他更改都会被阻止。 以前的脚本几乎没有涵盖 Subversion 书中描述的所有svnlook Changed ...
情况。Most of the previously written scripts are incomplete because several cases are not covered. This is my script:
It might seem complicated but you have to make sure that you are in
/tags
and you are allowed create/tags
if it does not exist and all subsequent folders. Any other change is blocked. Almost none of the previous scripts cover all cases described in the Subversion book forsvnlook changed ...
.接受的答案会阻止更新标签中的文件,但不会阻止将文件添加到标签中。 以下版本可以同时处理这两种情况:
The accepted answer prevents updating files in a tag but doesn't prevent adding files to a tag. The following version handles both:
我的版本只允许创建和删除标签。 这应该处理所有特殊情况(例如添加文件、更改属性等)。
My version only allows creating and deleting tags. This should handle all the special cases (like adding files, changing properties, etc.).
如果您使用的是 JIRA,则可以使用名为 提交策略来保护存储库中的路径而无需编写自定义挂钩。
如何? 使用名为已更改的条件文件必须与模式匹配。
它有一个正则表达式类型参数,该参数必须与提交中的每个文件匹配,否则提交将被拒绝。 因此,在您的情况下,您应该使用一个正则表达式,这意味着“不以前缀 /tags/ 开头”。
(您可以使用同一插件实现许多其他智能检查。)
免责声明:我是开发此付费附加组件的开发人员。
If you are using JIRA, you can use the add-on named Commit Policy to protect paths in your repository without writing custom hooks.
How? Use the condition named Changed files must match a pattern.
It has an regular expression type argument that must match for every file in a commit, otherwise the commit is rejected. So, in your case you should use a regex that means "does not start with the prefix /tags/".
(You can implement many other smart checks with the same plugin.)
Disclaimer: I'm a developer working on this paid add-on.
由于第一个答案没有阻止 add/suppr 文件,并且阻止了新标签的创建,以及许多其他不完整或有错误的地方,我重新设计了它,
这是我的预提交钩子:
目标是:
--------- 文件“预提交”(放入存储库 hooks 文件夹中) ---------
--------- 文件“预提交”结尾 ---------
另外,我制作了 2 个 shell 脚本来在每个项目中复制我的钩子我的 svn :
一种将存储库设置为只读:
--------- 脚本“setOneRepoTagsReadOnly.sh” ---------
--------- 文件结尾“setOneRepoTagsReadOnly.sh” - --------
为每个存储库调用它,使我的所有存储库只读:
--------- 文件“makeTagsReadOnly.sh” ---------
- -------- 文件“makeTagsReadOnly.sh”结尾 ---------
我直接从 svn “root”(/var/svn/repos/svn,在我的例子中)执行这些脚本。
顺便说一句,可以将 cron 任务设置为通过每天执行这些脚本来自动修改新的存储库
希望它有所帮助。
Since the 1st answer didn't prevent add/suppr files, and prevented new tags creation, and many other where incomplete or buggy, I reworked it
Here is my pre-commit hook :
Goals are :
--------- file "pre-commit" (put in repositories hooks folder) ---------
--------- end of file "pre-commit" ---------
Also, I made 2 shell scripts to copy my hook in every project of my svn :
One to set a repo read only :
--------- script "setOneRepoTagsReadOnly.sh" ---------
--------- end of file "setOneRepoTagsReadOnly.sh" ---------
And one calling it for every repo, to make all of my repos read only :
--------- file "makeTagsReadOnly.sh" ---------
--------- end of file "makeTagsReadOnly.sh" ---------
I execute thoses scripts directly from the svn "root" (/var/svn/repos/svn, in my case).
Btw, a cron task could be set to automatically modify new repos by executing thoses scripts daily
Hope it helps.
列出的答案很好,但没有一个完全符合我的需要。 我希望允许轻松创建标签,但是一旦创建它们,它们应该是完全只读的。
我还想防止出现愚蠢的情况,如果你这样做:
第一次一切都很好。 但第二次,如果标签已经存在,您最终将得到
myrepo/tags/newrelease/trunk
。我的预提交挂钩将查找任何与
(repo)/tags/(tag)/ 匹配的预先存在的 SVN 目录,如果找到则失败:
The listed answers are great but none did exactly what I need. I want to allow creating tags easily, but once they are created they should be fully read-only.
I also want to prevent the stupid situation where if you do this:
All is well the first time. But the second time, if the tag already exists, you will end up with
myrepo/tags/newrelease/trunk
.My pre-commit hook will look for any pre-existing SVN directory matching
(repo)/tags/(tag)/
and fail if it's found: