我想知道这里是否有人有编写此类脚本的经验,以及他们是否可以给我一些指导。
我想修改此 脚本 以验证签入文件在 EOL 格式中没有回车符。 EOL 格式在 Windows 中为 CR LF,在 Unix 中为 LF。 当用户使用 Windows 格式签入代码时。 它不再在 Unix 中编译。 我知道这可以在客户端完成,但我需要在服务器端完成此验证。 为了实现这一点,我需要执行以下操作:
1)确保我检查的文件不是二进制文件,我不知道如何使用 svnlook 执行此操作,我应该检查文件的 mime:type 吗? 红皮书没有明确指出这一点,或者我一定没见过。
2)我想运行 dos2unix 命令来验证文件具有正确的 EOL 格式。 我会将 dos2unix 命令的输出与原始文件进行比较。 如果两者之间存在差异,我会向客户发出错误消息并取消签入。
我希望得到您对这种方法的评论/反馈。
I was wondering if anyone here had some experience writing this type of script and if they could give me some pointers.
I would like to modify this script to validate that the check-in file does not have a Carriage Return in the EOL formatting. The EOL format is CR LF in Windows and LF in Unix. When a User checks-in code with the Windows format. It does not compile in Unix anymore. I know this can be done on the client side but I need to have this validation done on the server side. To achieve this, I need to do the following:
1) Make sure the file I check is not a binary, I dont know how to do this with svnlook, should I check the mime:type of the file? The Red Book does not indicate this clearly or I must have not seen it.
2) I would like to run the dos2unix command to validate that the file has the correct EOL format. I would compare the output of the dos2unix command against the original file. If there is a diff between both, I give an error message to the client and cancel the check-in.
I would like your comments/feedback on this approach.
发布评论
评论(2)
我认为在这种情况下,您可以通过使用 SVNBook 中所述的 svn:eol-style 属性来避免提交挂钩脚本:
行尾字符序列
Subversion 属性
这样 SVN 就可以为您处理行结尾。
祝你好运!
I think you can avoid a commit hook script in this case by using the
svn:eol-style
property as described in the SVNBook:End-of-Line Character Sequences
Subversion Properties
This way SVN can worry about your line endings for you.
Good luck!
你到底想做什么?
当然,有很多地方可以了解 svn 预提交钩子(例如 这里,此处,以及红皮书)但这取决于你想要做什么,并且您的系统上有什么可用的。
你可以说得更详细点吗?
What exactly are you trying to do?
Of course, there are numerous places to learn about svn pre-commit hooks (e.g. here , here, and in the Red Book) but it depends what you're trying to do and what is available on your system.
Can you be more specific?