How do I implement a pre-commit hook script in SVN that calls dos2unix to validate checked-in file
Asked Answered
Z

2

8

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.

Zaragoza answered 7/9, 2008 at 16:32 Comment(0)
O
4

I think you can avoid a commit hook script in this case by using the svn:eol-style property as described in the SVNBook:

This way SVN can worry about your line endings for you.

Good luck!

Obbard answered 8/9, 2008 at 19:45 Comment(2)
Thanks Stephen, I implemented the svn:eol-style property on all my source files instead of using pre-commit hooksZaragoza
What did you set it to? native or LF ? What is the default setting if svn:eol-style hasn't been set?Redstart
O
1

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?

Obbard answered 7/9, 2008 at 16:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.