In Git Bash:
$ notepad src/a.cs
unix2dos: src/a.cs MODE 0100644 (regular file)
unix2dos: using src/d2utmpLU38kg as temporary file
unix2dos: converting file src/a.cs to DOS format...
dos2unix: src/a.cs MODE 0100644 (regular file)
dos2unix: using src/d2utmppzFp4F as temporary file
dos2unix: converting file src/a.cs to Unix format...
$ where notepad
C:\Program Files\Git\usr\bin\notepad
...
If I have core.autocrlf on or text.auto set, opening a file in notepad changes all the line endings to LF after notepad exits. If I have either setting on, the conversion would be unnecessary anyway for files in the workdir.
It looks like this changed in GFW 2.5.3:
By configuring git config core.editor notepad, users can now use notepad.exe as their default editor. Configuring git config format.commitMessageColumns 72 will be picked up by the notepad wrapper and line-wrap the commit message after the user edited it.
I think that particular use case makes sense. Perhaps there's some way to only do the filtering inside the .git dir or for certain files, or only when editing commit messages, interactive rebase instructions, etc.? If someone is using notepad as their main editor they probably already have core.autocrlf or text=auto set anyway.
Also, the unix2dos/dos2unix trick works from git bash, but using notepad windows explorer is just as busted.
P.S. I never actually use notepad. I edit commit messages with VIM, and I use https://www.binaryfortress.com/NotepadReplacer/ to replace notepad w/ a better text editor (sublime or notepad++). Under the covers this uses the Debugger value in the Image File Execution Options reg key to set a "debugger" to run every time notepad.exe is run. See https://msdn.microsoft.com/en-us/library/a329t4ed(v=vs.100).aspx
So one thing we should do, I guess, is to convert line endings only when editing a file inside $GIT_DIR/...
I use https://www.binaryfortress.com/NotepadReplacer/ to replace notepad w/ a better text editor (sublime or notepad++). Under the covers this uses the Debugger value in the Image File Execution Options reg key to set a "debugger" to run every time notepad.exe is run. See https://msdn.microsoft.com/en-us/library/a329t4ed(v=vs.100).aspx
Could you tell me the tell-tale registry key? If the installer can detect its presence, it could also remove the notepad wrapper.
I think that limiting the EOL conversion to $Git_DIR/ would be sufficient. The conversion within $Git_DIR/ is harmless even if I'm using NotepadReplacer, and it seems like detecting NotepadReplacer would be extra work for a minor edge case. Also, What happens if I install Git for Windows and THEN install NotepadReplacer, or uninstall NotepadReplacer?
If you really want to go down the route of detecting notepad replacement, the value is
HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Image File Execution Options\n
otepad.exe\Debugger.
It's set to C:\Program Files (x86)\Notepad Replacer\NotepadReplacer.exe on my machine, but could easily theoretically be set to something else (I wrote my own arbitrary exe replacer a while ago).
What happens if I install Git for Windows and THEN install NotepadReplacer, or uninstall NotepadReplacer?
True. So the original idea is better.
If you're here because git config core.editor notepad annoyingly converts commit message files and the like to CRLF and then back to LF _but_ you have already replaced Notepad with a better editor through the well-known _Debugger_ registry hack, you can specify an absolute path and it will work without conversion:
git config core.editor C:/Windows/System32/notepad.exe
Note that it has to be forward slashes or double back slashes. This also works with git config --global.
@ADTC of course, you could also work on fixing this. The script in question is here: https://github.com/git-for-windows/build-extra/blob/master/git-extra/notepad and you could teach it e.g. to heed a notepad.eolConversion = false setting.
Note that by default it has to convert from LF to CRLF before editing when the file in question comes from Git, e.g. COMMIT_EDITMSG, because Notepad would show a single line otherwise for most users.
the well-known Debugger registry hack
Enlighten us. It is not as well-known as you think it is.
I could, but I'm not here to. I'm offering a workaround for those who have the problem in the current version, not a permanent fix they can get by adding a flag in the next version. I added it because this issue was the first hit when I searched about the problem, so I thought others might find it useful.
I also know very well the reason behind the conversion. Primitive Windows Notepad doesn't play nice with LF and I know that for a fact. This workaround is not meant for everyone, obviously. It's only meant for those who upgraded to a modern alternative, so that Git wouldn't unnecessarily do conversions when the installed alternative can correctly handle LF.
BTW, you can search the Internet for "how to replace notepad" and I'm positive you'll find the hack in the first 3 results. And besides, replacing installers like NotepadReplacer and Notepad2 installer are merely implementing this hack behind the scenes.
Honestly, instead of adding a flag, documenting it then blogging about it in tech blogs, and finally expecting everyone to upgrade to the latest version just so they can use it, simply changing to the absolute path is far easier to implement and talk about. But I apologise if I appear to add no value to this discussion.
FWIW, this notepad script didn't convert when I was doing git config --global -e. Maybe someone should fix that first before talking about adding a conversion flag.
Maybe someone should fix that first before talking about adding a conversion flag.
Maybe you could stop suggesting what other people should work on, given that you declined when I suggested you should do some work. I mean, fair is fair, right? 馃槃
Sorry for the butthurt feelings 馃槃馃槃馃槃
Peace!