Subversion and the incoherent linebreak problem

When trying to commit code into a subversion repository, and if the code you want to submit comes from third parties, you might occasionally run into the error “incoherent linebreak”.

This is due to people editing files from Windows, Linux and Mac, which all have different line break characters. Under Windows, it’s rn, under Mac it’s r and finally under Linux it’s n.

Depending on what system you are usually using to commit your code to SVN, you should replace all the others for yours. This is easily done by asking all external contributors to change their text editor settings to “Linux linebreaks” for example.

If the code you are trying to submit comes from a PHP generator (some translation interface), you can use the following code to do that:

$string = str_replace(array("rn","r"),array("n","n"),$string);

If you are reviewing files with VIM, you should be able to do something like:

:% s/rn/n/g
:% s/r/n/g

Then try to commit again. The incoherent linebreak error should have disappeared.