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?
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?
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).
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.
you can use notepad++ to batch convert line endings. Make regex search:
([^\r])\n
and replace it with
$1\r\n
you then should choose a bunch of test files like:
*.xml;*.txt;*.csv;...
asf.
this avoids that you accidently modify binary files
NOTE: the regex patterns skip empty lines, so you have to run a second replace job with \n\n
and replace it with \n\r\n
© 2022 - 2024 — McMap. All rights reserved.