How to implement a pre-commit script hook in SVN that calls dos2unix to validate a registered file

I was wondering if anyone here has experience writing this type of script, and if they could give me some pointers.

I would like to modify this script to confirm that the log file does not have a carriage return in EOL format, EOL format is CR LF on Windows and LF on Unix. When the user checks the code in Windows format. It no longer compiles on Unix. I know that this can be done on the client side, but I need this check to be done on the server side. To do this, I need to do the following:

1) Make sure the file I'm checking is not binary, I don’t know how to do it with svnlook, should I check the mime: type type? The Red Book does not indicate this explicitly or I must not have seen it.

2) I would like to run the dos2unix command to verify that the file has the correct EOL format. I would compare the output of the dos2unix command with the source file. If there is a difference between the two, I give an error message to the client and unregister.

I would like to receive your comments / feedback on this approach.

+7
python svn dos2unix
source share
2 answers

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

In this way, SVN can worry about your line endings for you.

Good luck

+4
source share

What exactly are you trying to do?

Of course, there are many places where you can learn about svn pre-commit hooks (for example, here , here , and in the Red Book ), but it depends on what you are trying to do and what is available on your system.

Can you be more specific?

+1
source share

All Articles