lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Add support for difftastic?

Open pvonmoradi opened this issue 3 years ago • 7 comments

difftastic is a diff tool which is aware of the semantics of the code depending on their programming language.

I was wondering if it is possible to integrate it into lazygit as a custom diff tool. I've tried adding it to lazygit config as a custom pager like this:

git:
  paging:
    colorArg: always
    pager: difft

but I guess this is not the correct way of doing it since it prints its --help in diff section.

pvonmoradi avatar Apr 01 '22 17:04 pvonmoradi

same issue, would love to see difftastic supported

RaafatTurki avatar Apr 08 '22 04:04 RaafatTurki

It should be fairly easy to set up, though admittedly after a few minutes reading the docs I haven't been able to get it working. Not sure if we need a code change on the lazygit side or if it's just a matter of coming up with the right command template in the config

jesseduffield avatar Apr 09 '22 22:04 jesseduffield

Not sure if we need a code change on the lazygit side or if it's just a matter of coming up with the right command template in the config

Is there a way to pass env. vars to lazygit? Does lazygit invoke git diff using some sort of os routine or does it directly use git libraries? GIT_EXTERNAL_DIFF='difft --display inline' git diff uses difft (with paging) but GIT_EXTERNAL_DIFF='difft --display inline' lazygit does not.

btw, difft version 0.26 added a --display switch which accepts an inline value which may be more proper for lazygit since the side-by-side mode may not fit in the main pane.

pvonmoradi avatar Apr 11 '22 09:04 pvonmoradi

Lazygit invokes git as a subprocess, and for the pager we use the GIT_PAGER env var e.g. GIT_PAGER=difft. So perhaps we could conditionally use GIT_EXTERNAL_DIFF instead of GIT_PAGER?

jesseduffield avatar Apr 11 '22 11:04 jesseduffield

when I run GIT_EXTERNAL_DIFF=difft git diff in the CLI that works fine, but when I do cmd.Env = append(cmd.Env, "GIT_EXTERNAL_DIFF=difft") in pkg/gui/pty.go:53 (newPtyTask function) it appears like the regular diff mode

jesseduffield avatar Apr 11 '22 11:04 jesseduffield

Any status on this?

OlaoluwaM avatar Aug 13 '22 03:08 OlaoluwaM

So the difference to other tools is that difftastic is an alternative diff tool while e.g. diff-so-fancy is implemented as a pager?

Would be nice if git config --global diff.external difft would be sufficient to convince lazygit to pick it up. Might be that some heuristic or an additional switch is needed to support diff.external as well as core.pager.

It looks like lazygit currently prevents this by setting -no-ext-diff.

aruediger avatar Sep 09 '22 09:09 aruediger

Any status update on this, pls?

MSDimos avatar Sep 29 '22 03:09 MSDimos

@aruediger we can make that --no-ext-diff thing configurable. Would that suffice? Happy to accept a PR for this

jesseduffield avatar Sep 29 '22 03:09 jesseduffield

@aruediger I tested your idea. Unfortunately, lazygit's hunk parsing algorithm is not compatible with difftastic's output format, even with inline display set. It results in something like this:

截屏2022-11-10 02 32 10

PhotonQuantum avatar Nov 09 '22 18:11 PhotonQuantum

@PhotonQuantum Bummer. (Was just about going to look into it myself.)

@jesseduffield How hard would it be to teach lazygit to deal with difftastic's chunk format?

aruediger avatar Jan 10 '23 12:01 aruediger

Fwiw: it would be great to interactively switch between various differs / pagers. Most of the time I prefer difftastic, but it would be nice to switch over to delta without leaving lazygit.

hacker-DOM avatar May 18 '23 22:05 hacker-DOM

Fwiw: it would be great to interactively switch between various differs / pagers. Most of the time I prefer difftastic, but it would be nice to switch over to delta without leaving lazygit.

Does that mean you have a working setup of lazygit using difftastic? Would you mind sharing your config?

alex007sirois avatar May 23 '23 12:05 alex007sirois

People are Dming me to send them my config 😂 I was just pointing out that once we do figure out a way to integrate them, we shoud want to be able to switch on the fly. I use lazygit from neovim and the speed difference between being able to switch on the go, and closing lazygit, editing my config, and relaunching it (or potentially all of neovim) is like 1000x. So no, I do not have it working.

hacker-DOM avatar Jun 27 '23 07:06 hacker-DOM

Here's a PR that adds support for difftastic: #2868. Testing and feedback welcome.

However, I have to say that I'm a little underwhelmed. There are a few cases occasionally where difftastic does a great job at rendering the diff; for example in go code when indentation changes, like here. However, in most cases like this I can get a very similar result from any other pager by simply hitting <c-w> to ignore whitespace. For the vast majority of my work, I still greatly prefer delta's output.

I suppose people working in other programming languages than I do might find it useful more often.

I agree with the comments above that suggest to add a keybinding to cycle through pagers. I don't want this badly enough myself to explore this any time soon, though.

stefanhaller avatar Aug 03 '23 09:08 stefanhaller

Closing this as #2868 is on master now.

stefanhaller avatar Sep 20 '23 12:09 stefanhaller

Do we know when this feature will be released? In other words, do we have an ETA on the next release?

alex007sirois avatar Sep 25 '23 15:09 alex007sirois