Question

So, you are all ready to do a big SVN Commit and it bombs because you have inconsistent line endings in some of your files. Fun part is, you're looking at 1,000s of files spanning dozens of folders of different depths.

What do you do?

Was it helpful?

Solution

I don't think the pre-commit hook can actually change the data that is being committed - it can disallow a commit, but I don't think it can do the conversion for you.

It sounds like you want the property 'svn:eol-style' set to 'native' - this will automatically convert newlines to whatever is used on your platform (use 'CRLF', 'CR' or 'LF' to get those regardless of what the OS wants).

You can use auto-properties so that all future files you create will have this property set (auto props are handled client-side, so you'd have to set this up for each user).

OTHER TIPS

First is to clean everything up. Are you on Windows or Unix/Linux/Mac?

If you're on Unix/Linux/Mac, you can try something like this:

$ find . -type f -name "*.java" -exec dos2unix {}\;

That's if you have dos2unix on your box. It's not on my Mac or any of the six Linux machines we have. Seems like we didn't install this particular package. Fortunately, it's easy enough to find.

Be careful using it because you don't want to to munge binary files.

Once you've cleaned everything up, you should put the svn:eol-style property on your files. Setting it to native will checkout the file with the correct line ending for your machine, but store them in Unix line ending format. The other three options are "LF" for Unix, "CRLF" for Windows, and "CR" for pre Mac OS X Macs. Most people find "native" to work out the best. The only problem with Native is that it won't check in a file with mixed line endings while "LF" and "CRLF" will.

Once you do that, you should get a pre-commit hook that will allow you to enforce line endings on particular files. Then, teach your developers to use autoproperties. The pre-commit hook will prevent any commits unless the property is placed on the file A developer gets their commit rejected once or twice, and they'll setup auto properties on their own.

Add a pre-commit hook which parses the file content and performs the munging of CRLF/LF/CR/etc for you before it's written to SVN.

You may consider using a command like Linux's dos2unix for the conversion. Being a Linux command, it is easy to use it in batch mode with scripts etc. I do not know whether there is an equivalent for other operating systems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top