jesseduffield / lazygit

simple terminal UI for git commands
MIT License
52.66k stars 1.84k forks source link

Config option to change diff algorithm #3984

Closed alexgokhale closed 1 day ago

alexgokhale commented 3 weeks ago

Is your feature request related to a problem? Please describe. I understand that ignoring whitespace is already possible with <c-w>, but it would be ideal for certain changesets to be able to switch to using the patience diff algorithm.

Describe the solution you'd like A config option that enables users to choose which algorithm to use for generating diffs.

Describe alternatives you've considered I appreciate that you can use an external paging/diff application, but I'd rather use functionality that's already built into git (if possible).

Additional context I'd be very happy to make a PR for this, I'm mainly opening an issue to check that there isn't something obvious I'm missing which would allow me to achieve this functionality without code changes.

stefanhaller commented 2 weeks ago

I'm not against this, but the challenge is how to do the UX for it. Users want to set all sorts of diff options besides "ignore whitespace" (see #800 for some), and adding new keybindings (like with <c-w>) for all of them doesn't scale well. Also, we'd probably want to display them all in the upper right corner of the diff window, like we do for (ignoring whitespace) now, and there isn't an infinite amount of space there.

It might be best to have some sort of dialog with options (checkboxes) for the various things that you may want to turn on and off, but that makes it a pretty big task with quite a few open questions. (For example, it would make <c-w> less convenient, requiring at least two keystrokes for that. I don't have a good idea how to solve that.)

In the meantime, a custom command like this one can approximate it:

customCommands:
    - key: <whatever>
      command: git config diff.algorithm {{.Form.algorithm}}
      prompts:
        - type: menu
          title: "Diff Algorithm"
          key: "algorithm"
          options:
            - value: "default"
            - value: "minimal"
            - value: "patience"
            - value: "histogram"
      context: "global"
      description: "Choose diff algorithm"

Of course, the downside is that the last chosen algorithm sticks around and stays effective outside of lazygit. Or maybe that's not a downside at all, depending on how you look at it. 😄

alexgokhale commented 1 day ago

Sorry for the delay in replying to this.

I think you're right that the algorithm can be configured outside of lazygit and will stick around, which is probably the correct level at which to configure it. I don't really envisage a situation in which you'd want to regularly switch between diff algorithms only in a lazygit environment.

Happy to close this issue and either use a custom command or set this in the global git config. Thanks for the help!