git-for-windows / git

A fork of Git containing Windows-specific patches.
http://gitforwindows.org/
Other
8.28k stars 2.51k forks source link

Weird interaction with git add -p and Notepad++ (git hangs) #4776

Open klylesatepic opened 7 months ago

klylesatepic commented 7 months ago

Previously reported at https://github.com/microsoft/terminal/issues/16553 and https://github.com/msys2/msys2.github.io/issues/307.

Setup

$ git --version --build-options
git version 2.43.0.windows.1
cpu: x86_64
built from commit: 4b968f3ea3b32a7bc50846bab49f3f381841d297
sizeof-long: 4
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
$ cmd.exe /c ver

Microsoft Windows [Version 10.0.19044.3930]
# One of the following:
> type "C:\Program Files\Git\etc\install-options.txt"
> type "C:\Program Files (x86)\Git\etc\install-options.txt"
> type "%USERPROFILE%\AppData\Local\Programs\Git\etc\install-options.txt"
> type "$env:USERPROFILE\AppData\Local\Programs\Git\etc\install-options.txt"
$ cat /etc/install-options.txt

Editor Option: VIM
Custom Editor Path:
Default Branch Option: main
Path Option: Cmd
SSH Option: OpenSSH
Tortoise Option: false
CURL Option: WinSSL
CRLF Option: CRLFAlways
Bash Terminal Option: MinTTY
Git Pull Behavior Option: Rebase
Use Credential Manager: Enabled
Performance Tweaks FSCache: Enabled
Enable Symlinks: Disabled
Enable Pseudo Console Support: Disabled
Enable FSMonitor: Enabled

I don't think so, but I'm happy to answer further questions.

Details

Git Bash in Windows Terminal

  1. Open Git Bash in Windows Terminal
  2. Navigate to a git repository
  3. Make changes in at least two separate places in a file
  4. Run GIT_EDITOR='"C:\Program Files\Notepad++\notepad++.exe" -multiInst -notabbar -nosession -noPlugin' git add -p to interactively stage parts of the file
    • Obviously you will need Notepad++ installed, and you may need to adjust the path to it
  5. Type e to edit the first hunk (Notepad++ will open)
  6. Make whatever change you like within one of the new lines (starting with a plus)
  7. Save and close Notepad++
  8. See that git moves on and prompts for the next hunk
  9. Try to type n to skip the next hunk (or anything else)
  10. See that git is stuck (Ctrl+C won't interrupt it)

The same issue happens with git add -i instead of git add -p, but requires more steps between steps 4/5.

The issue does not happen if any of the following are true:

Input would be accepted for dealing with the next hunk, and git would not hang.

Input is not accepted (or at least not echoed), and git hangs.

Not repository specific.

richbern commented 3 months ago

Experiencing this issue and want to track any updates. I prefer notepad++ as my general quick editor and would prefer not to have to change that or remember to change the editor before doing an add -i.

ehm214 commented 1 month ago

In case it helps, I'm pretty sure I'm experiencing the same issue with VSCode as my editor.

The steps to reproduce are the same, except for step 4, you want GIT_EDITOR="code --wait" assuming you have VSCode in your PATH.

I switched to using vanilla Git Bash for the file where I was experiencing the issue as a workaround.