fork-dev / TrackerWin

Bug and issue tracker for Fork for Windows
467 stars 10 forks source link

EOL confusion #1650

Open JeReT opened 2 years ago

JeReT commented 2 years ago

When there is a file which only changed the line endings, fork will show that this file contains changes. When you then stage the file, the file simply disappears. Not sure if this has to do with my git settings.

Steps to reproduce:

  1. create a txt file in a repository and add some text with some new lines (Windows style: CR+LF)
  2. commit this file
  3. change the EOL to a different style (Unix Style: LF)
  4. open the repository with Fork
  5. in the changes section find the changed file and click "Stage"

Result: the file disappears.

Expected Result: one of these:

  1. The file doesn't appear in the changes view and therefore cannot be staged.
  2. The file is part of the commit and doesn't disappear when staged.

(I prefer version 1, but it should probably be different depending on the whitespace settings of the git config. But I'm no git config expert...)

DanPristupov commented 2 years ago

git config core.autocrlf

https://www.git-scm.com/book/en/v2/Customizing-Git-Git-Configuration

Git ... auto-converts CRLF line endings into LF when you add a file to the index, and vice versa when it checks out code onto your filesystem. You can turn on this functionality with the core.autocrlf setting. If you’re on a Windows machine, set it to true — this converts LF endings into CRLF when you check out code:

DanPristupov commented 2 years ago

So, if you need, you can disable autocrlf globally (git config --global), per repository(git config --local) or per folder/file (.gitattributes).

JeReT commented 2 years ago

Thanks for the reply but I don't think this helps. I have some auto-generated files in my project which always seem to have the wrong line ending. It clutters my changes view. What can I do about it?

DanPristupov commented 2 years ago

I have some auto-generated files in my project which always seem to have the wrong line ending.

I assume you mean the auto-generated files have the unix (LF) line endings, but the rest of the repository is in windows format (CRLF).

Then you should tell git that those files have unix line endings by adding to the.gitattriebutes file the following:

path/to/autogenerated/files/*.txt eol=lf
JeReT commented 2 years ago

Funny, I actually did this in the past. I have to investigate the files I talk about a bit, because sometimes the changes appear and sometimes not. But probably your suggestion will fix it.

Would be nice if I could do this inside fork: If a file doesn't have a diff, fork could show an info: "Line endings detected as [eol-style]" and a button: "Configure line endings". When you press the button, a dialog appears where you can specify the eol style (the one from the file by default) as well as the path (path to the file by default). When confirming, the .gitattributes are modified.