+35
Started

Show all modified line endings in diff viewers

ubruhin 11 months ago • updated by ck05 5 months ago 12

Until now, modified EOLs are nearly not visible in SmartGit. There's only a label which shows for example "EOL: Unix vx. Windows", but it's very easy to overlook it because the diff itself shows no changes.


In addition, if a file has different EOLs, SmartGit just says "EOL: Mixed" but does not show which line has which line ending. And staging/discarding them line by line is also not possible.


In my opinion, differences in EOLs should be visible in diff viewers with some kind of symbol on each line, like "git diff" does. So the user can see which line has which line ending, and can even fix them by staging or discarding line by line, just like all other changes.


This feature may be useless on Windows with "core.autocrlf=true", but on other operating systems or with "core.autocrlf=false" this would be extremely helpful because one can see and fix introduced EOL changes.

+2

There should also be a warning when you try to commit a file with inconsistent line endings.

All the other tools we tried show lines ending changes: SourceTree, TortoiseGit, Tower, GitLab.

To make the programmer aware of the diff is essential in order to prevent "Wall of Pink" problems (https://www.hanselman.com/blog/YoureJustAnotherCarriageReturnLineFeedInTheWall.aspx)

The devil is in the detail, e.g.: what line separator to enter when the user presses <enter>, especially if the file is empty. How to handle text copy-pasted from some other source?

Many questions indeed, and as always with this subject, opinions differ.

Git is pretty confusing with 2 settings for this (core.eol, core.autocrlf) (+core.safecrlf and .gitattributes).


> what line separator to enter when the user presses <enter>

Most tools I know insert native carriage return. Visual Studio on Windows in particular insert CRLF (native), even in non-mixed Linux (LF) or Mac OS9 (CR) files

> How to handle text copy-pasted from some other source?

Most tools I know keep the source format (and thus can create mixed files)


The important part is seeing the change in the diff view

SmartGit should not be a bad editor and support/write mixed line separators. If mixed line separators were detected, it will reject editing.

This is the correct theoretical thing to do, but...

Our source code was edited on 5 different platforms over more than 20 years. Many "bad" editors were used. Now every file we have has mixed line endings.

In effect, the SmartGit editor would be disabled on all our files.

In my opinion, the best thing to do would be what I described earlier.

The second best thing would be to uniformize the line endings on edition, with a warning (with a "do not show again" checkbox).

In your case I recommend to use a tool that simply fixes all line separators. This is, IMHO, not the task of a version control client.

+1

> what line separator to enter when the user presses <enter>, especially if the file is empty. How to handle text copy-pasted from some other source?


Some (good) editors have options to configure the behavior for that. So it's possible to specify the default line ending in the editor preferences, this line ending is then used when editing an empty file. If there are already lines in the file, pressing <enter> or pasting text into the file should always use the same line ending as already used in the file (auto detection). IMHO this is a good option for most of the possible use cases.


> If mixed line separators were detected, it will reject editing.


I would not do that as it can be annoying in some situations. I would strongly prefer a warning which is shown when editing a file with mixed line endings. Maybe even with an option to convert all line endings to LF or CRLF.

17.1 preview 12 #11103

I like the new carriage return diff view.


I wanted to disable this option to look "at true changes" (ignoring carriage return).

But it seems that the "built-in file compare" (separate windows) and the "changes" (quick view tab) don't use the same settings?

I expected "Ignore whitespace for line comparaison"  to have effect on this, for both tools.

The File Compare (standalone window) only lets you edit the file content (no display of different line separators), except of the case of mixed line endings where editing is prevented. Please use Help | Check for Latest Build to get #11105 - then you will find an option to "Ignore Line Separator Changes".

Could we please get an option to make these settings (ignore line endings) enabled by default? Many other compare tools can do that.

While I welcome the possibility to view line ending changes, they usually obfuscate any other changes in the file. If the option will not be implemented, please consider to change the color of the line ending diff marks, so it is easy to separate them from content changes.