Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Delta as diffFilter breaks keyboard input with git add -p in Git CMD #1650

Open
imbrish opened this issue Mar 9, 2024 · 13 comments
Open

Comments

@imbrish
Copy link
Contributor

imbrish commented Mar 9, 2024

With the following configuration in git config:

[interactive]
    diffFilter = delta --color-only
[alias]
    ap = "!git add -p"

The keyboard input does not work at all when git ap asks:

(1/1) Stage this hunk [y,n,q,a,d,e,?]?

Even Ctrl + C does nothing, the only way to stop is with Ctrl + Z.

This happens when using git-cmd but not when using git-bash.

The keyboard works normally with either of the changes below:

[interactive]
    diffFilter = diff-so-fancy --patch
[interactive]
    diffFilter = delta --color-only | cat
[alias]
    ap = add -p

This seems like some race condition. Not sure if the problem is specific to delta, but then diff-so-fancy works fine.

Is there something else I could try to debug this?

@hintron
Copy link

hintron commented Mar 19, 2024

Same here, when I start Git Bash under Windows Terminal 1.19.10573.0. I have Delta 0.16.5 (also happens with 0.17.0) and Git Bash 2.40.1.1. However, when I run git-cmd or git-bash directly, and not under Windows Terminal, I don't hit the issue.

@hintron
Copy link

hintron commented Mar 19, 2024

When I upgraded to Git 2.44.0.1, it mostly behaves the same, except if I hold ctrl and hit enter, I can get it to re-display the prompt, and sometimes a ctrl-C goes through. Also, the line number vertical bars are replaced with Γï« and Γöé (but they show up normal as : and | when I do git diff standalone).

BTW my .gitconfig contains

[core]
        pager = delta

[interactive]
        diffFilter = delta --color-only

[delta]
        features = mgh_decorations
        line-numbers = true
        whitespace-error-style = 22 reverse

[delta "mgh_decorations"]
        commit-decoration-style = bold green box
        file-style = bold yellow
        file-decoration-style = bold yellow ul
        hunk-header-decoration-style = purple box

@Bouska
Copy link

Bouska commented Mar 25, 2024

I have also the same issue (except is replaced by Ôï« and by Ôöé) using delta 0.17.0 (copied from MSYS2/MINGW64), Windows Terminal 1.19.10573.0 and git 2.44.0.windows.1 (Git Bash). But using the same configuration with git version 2.44.0 (from MSYS2/MINGW64) works as expected. So I guess the git exe from Git Bash doesn't like the delta exe (copied from MSYS2/MINGW64) when executed under Windows Terminal (really a weird race condition)

@Bouska
Copy link

Bouska commented Mar 25, 2024

After some investigation, I'm not so sure this is a bug in delta. Under the hood, git calls an equivalent to git diff-files --color --ignore-submodules=dirty -p -- | delta --color-only and this command works perfectly fine.

@imbrish
Copy link
Contributor Author

imbrish commented Mar 25, 2024

I am not sure your problem is the same as mine, it seems like some encoding issue. Have you tried running chcp 65001 (or chcp.com 65001) prior to the command you have trouble with?

I have this in my .bashrc and have not seen any such problems, also with the same git version you reference.

@Bouska
Copy link

Bouska commented Mar 26, 2024

I still think we have the same problem, the main issue I have is that (1/1) Stage this hunk [y,n,q,a,d,e,?]? doesn't accept any input, ctrl-c doesn't work either, only ctrl-z works (and the next hunk is shown before I get the prompt back). The encoding issue seems to be only a side effect.

@Bouska
Copy link

Bouska commented Mar 26, 2024

@imbrish chcp.com 65001 fixes my encoding issue 👍 but still have the main issue

@imbrish
Copy link
Contributor Author

imbrish commented Mar 26, 2024

Glad it helped 👍

I think the broken keyboard input is mostly a problem with Git for Windows and how it interacts with Command Prompt or Terminal. Actually, it seems it is not the input that is broken, but the output, because I am still able to go through the git add --patch in blind, and the changes do get staged. This is made even more apparent when using ctrl + enter.

I have also experienced similar issues before I started to use Delta. For example, using a shell command (with !) for textconv would break mouse scrolling in diffs paged with less. I am not entirely sure what happens there, but it seems to have something to do with registering of mouse and keyboard hooks.

Anyway, I have also tried the following in git config:

[interactive]
    diffFilter = delta --color-only --paging=never

But it does not change anything, the problem is exactly the same as originally described. Only piping through cat helps. I have no clue why that is.

@dandavison possibly you could point us where to look? What exactly does delta do differently when its output is piped and when it is not? I would imagine delta --color-only --paging=never should be equivalent to delta --color-only | cat, but apparently it is not. May it be that git detects pipe in the diffFilter, and then runs it differently?

@Bouska
Copy link

Bouska commented Mar 26, 2024

Here is the Git code that interest us: add-patch.c#L403
So basically what git does in our case is:

  • run git diff-files --no-color --ignore-submodules=dirty -p -- and store the result in a buffer plain
  • run git diff-files --color --ignore-submodules=dirty -p -- and store the result in a buffer colored
  • pipe the content of the buffer colored to the command of interactive.diffFilter and store the result in colored
  • parse the content of plain to split the diff into hunks and find the offset of each line in colored

As I said before, git diff-files --color --ignore-submodules=dirty -p -- | delta --color-only works fine, so I'm guessing its finding the equivalent hunks in the colored buffer that triggers the issue.

@imbrish
Copy link
Contributor Author

imbrish commented Mar 26, 2024

Investigating at the source 😉

If the problem lies in matching the plain and colored hunks, then why would ... | cat fix it? The output stays the same.

I wonder if this works only in Command Prompt. Have you tried diffFilter = delta --color-only | cat in Windows Terminal?

@Bouska
Copy link

Bouska commented Mar 26, 2024

I tried diffFilter = delta --color-only | cat yesterday and it would still freeze, but I tried today and it works (but not exactly in the same conditions) 🤷

@adriencarbonaro
Copy link

Hello,
I also have the same issue. I think it is a git for windows or windows terminal issue, as git bash works as intended. I also tested with same version of delta on another (older windows) computer and it works. The only change is the version of windows itself (10 vs 11) and git for windows (2.30 vs 2.44)

@stefan-muc
Copy link

stefan-muc commented May 24, 2024

I have a somehow related issue: I experience the freeze on git add -p with VSCode/VSCodium Git bash (MINGW64) terminal, but not in native Git CMD/Bash started through start menu / context menu in explorer.
Can confirm imbrish discovery that if I continue "blind" the changes get indeed added.

Versions: VSCode/VSCodium 1.89.1 (system setup)
Git: git version 2.45.1.windows.1
Windows: Win 10 22H2 Build 19045.4412 (VSCode and VSCodium), Win 11 23H2 Build 22631.3593 (only VSCode tested)
.gitconfig: Default example as in Get Started - without delta there's no freeze.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants