Subversion 空白删除提交钩子

发布于 2024-08-10 02:07:23 字数 225 浏览 5 评论 0原文

Jeff Atwood 写了空格,并建议创建 commit 钩子,以删除末尾的空格行和文件的结尾。

我已经搜索过,但没有找到使用 pre-commit 钩子来修改这样的文件的明确示例。您有想要分享的脚本吗?

Jeff Atwood wrote about whitespace and suggested creating commit hook which removes trailing whitespace at the ends of lines and files.

I've searched, but I haven't found a clear example of using a pre-commit hook to modify files like this. Do you have a script which you'd like to share?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时常饿 2024-08-17 02:07:23

I'm pretty sure that pre-commit hooks can't be used to modify the transaction in progress. It can only allow or deny the commit action. In your case, you'd want to examine the files to see if they meet your whitespace requirements and fail the commit with a useful error message if they do not. You could use a post-commit hook to do what you propose, but it would involve making a second commit from the hook script to fix the bad whitespace in the first commit. I think the pre-commit hook approach is better.

凉世弥音 2024-08-17 02:07:23

在 subversion 中你不能真正使用提交钩子来做到这一点,因为如果服务器修改了文件,它将与客户端上的版本不匹配。提交挂钩用于只读事件,例如生成通知消息,或通过检查文件来查看是否应阻止提交。

请参阅有关提交挂钩的文档

挂钩是由某些存储库事件触发的程序,例如创建新版本或修改无版本属性。一些钩子(所谓的“预钩子”)在存储库操作之前运行,并提供一种方法来报告即将发生的情况并阻止其发生。其他挂钩(“后挂钩”)在存储库事件完成后运行,对于执行检查(但不修改)存储库的任务很有用。每个钩子都会获得足够的信息来说明该事件是什么(或曾经是)、建议(或完成)的特定存储库更改以及触发该事件的人员的用户名。

You can't really use commit hooks to do this in subversion, because if the file is modified by the server, it will not match the version on the client. Commit hooks are for read-only events such as generating notification messages, or by checking the files to see if the commit should be blocked.

See the documentation on commit hooks:

A hook is a program triggered by some repository event, such as the creation of a new revision or the modification of an unversioned property. Some hooks (the so-called “pre hooks”) run in advance of a repository operation and provide a means by which to both report what is about to happen and prevent it from happening at all. Other hooks (the “post hooks”) run after the completion of a repository event and are useful for performing tasks that examine—but don't modify—the repository. Each hook is handed enough information to tell what that event is (or was), the specific repository changes proposed (or completed), and the username of the person who triggered the event.

笔落惊风雨 2024-08-17 02:07:23

不确定您所在的平台,但您可以使用 TortoiseSVN 来执行此操作,使用其 客户端挂钩

本质上,您将编写一个脚本来使用预提交挂钩修改文件。我认为在构建脚本中这样做更正确:您实际上不想提交甚至还没有编译或运行的代码!删除空格的脚本可能会破坏某些内容,具体取决于上下文/语言。

Not sure what platform you are on, but you can do this with TortoiseSVN, using its client-side hooks.

Essentially you would write a script that would modify the files using a pre-commit hook. I think this is more correctly done in a build script though: you don't really want to commit code you have not even compiled or run! Your script that removes spaces could potentially break something, depending upon the context/language.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文