delta
delta copied to clipboard
🐛 git-delta munges filenames with hyphens
Reproduction steps:
Setup:
cd $(mktemp -d git-delta-bug-XXXX)
git init
echo hello > some-file
git add some-file
git commit -m some-file
Symptoms: -
in file name is replaced with :
:
git grep hello; git grep -l hello
returns:
some:file:hello
some:file
instead of the expected no-pager output of:
git --no-pager grep hello; git --no-pager grep -l hello
which yields:
some-file:hello
some-file
Version:
$ delta --version
delta 0.15.1
Hello,
It looks like the hyphens are also replaced in the branch names, not just the filenames, e.g.:
$ git grep --no-pager mptcp_ t/upstream-net
t/upstream-net:<file>:<match> ## without Delta
(...)
$ git grep mptcp_ t/upstream-net
t/upstream:net:<file>:<match> ## with Delta
(...)
(with Delta, we have t/upstream:net
instead of t/upstream-net
for the branch name)
Hi @nickurak @matttbe ultimately the problem here is that traditional grep output is not unambiguously parseable, due to the use of characters as delimiters which might also occur in file names. That said, it definitely might be possible to fix the bugs you're highlighting. Check out the (not nice) code which explains the problem and the attempts to solve it by trying various regexes: https://github.com/dandavison/delta/blob/ce41a39bf6ebd3b7bbac4c73954cf6078ed96fc5/src/handlers/grep.rs#L320-L325 If you can see how to improve that code and make it work for a larger set of inputs I'd be happy to accept changes: the code does at least have decent unit tests so you can experiment with different approaches fairly easily.
Personally, I would say the best solution is to use ripgrep --json | delta
, which of course has no parsing ambiguities. However, I understand that git grep
provides some functionality that ripgrep doesn't.
I just hit this and got incredibly confused when git grep
was telling me about files that don't exist.
@rossburton is it possible for you to use rg --json
instead? The delta manual contains an entry addressing this:
If you don't need special features of git grep, then for best results pipe rg --json output to delta: this avoids parsing ambiguities that are inevitable with the output of git grep and grep.
Copying from #1631
See the ~500 lines of unit tests here: https://github.com/dandavison/delta/blob/main/src/handlers/grep.rs#L653-L1177. If someone can improve the parsing while keeping all those tests passing (and hopefully adding a test for what you're fixing) that would be fantastic.
I'm going to close this since I have personally taken a fairly large stab at it and also implemented rg --json
support for a fully robust solution.