Subversion 空白删除提交钩子
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我很确定 预提交挂钩< /a> 不能用于修改正在进行的事务。它只能允许或拒绝提交操作。在您的情况下,您需要检查这些文件以查看它们是否满足您的空白要求,如果不满足,则提交失败并显示有用的错误消息。您可以使用提交后挂钩来执行您建议的操作,但这将涉及从挂钩脚本进行第二次提交以修复第一次提交中的错误空白。我认为预提交挂钩方法更好。
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.
在 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:
不确定您所在的平台,但您可以使用 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.