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

Support diff-so-fancy patch mode by using --patch when building code sets #4201

Open
scottchiefbaker opened this issue Jan 22, 2025 · 3 comments · May be fixed by #4332
Open

Support diff-so-fancy patch mode by using --patch when building code sets #4201

scottchiefbaker opened this issue Jan 22, 2025 · 3 comments · May be fixed by #4332
Labels
enhancement New feature or request

Comments

@scottchiefbaker
Copy link

I have Lazygit configured to use diff-so-fancy per your excellent documentation. I would love to see Lazygit support d-s-f while in patch mode also. If a user wants to include parts of a file in their commit they can run git add . --patch and d-s-f will highlight the patch pieces appropriately.

Is it possible for Lazygit to use --patch for it's internal patch mode text selection?

-- Scottchiefbaker / Diff-so-Fancy lead developer

@scottchiefbaker scottchiefbaker added the enhancement New feature or request label Jan 22, 2025
@stefanhaller
Copy link
Collaborator

Hi Scott, sorry for not responding earlier.

Is it possible for Lazygit to use --patch for it's internal patch mode text selection?

Yes, this might be possible. It would require adding a separate pager config to lazygit that is used only for the staging panel. Lazygit would then have to run the diff twice, once without pager for the internal patch logic, and again with the pager for display; it could verify that the number of lines returned by each is the same, to double-check that users didn't forget the --patch option (or --color-only if they are using delta). It seems that git add -p makes the same check, because it shows an error if I set interactive.diffFilter to diff-so-fancy without --patch.

It's not an easy change though; I remember that I briefly looked into it a while ago, and found it to be more effort than I was willing to spend at that time. I might look into it again when I find the time, but I'm also happy to support anyone who wants to give it a try.

@scottchiefbaker
Copy link
Author

The more I think about it... you may not even need our --patch mode. A simple git diff in diff-so-fancy output would be sufficient if you break the chunks up in lazygit.

All git add --patch does is get you the "y/n/s" options for each chunk. Lazygit does that all internally.

@stefanhaller stefanhaller linked a pull request Feb 26, 2025 that will close this issue
@stefanhaller
Copy link
Collaborator

Yes, --patch is needed in lazygit, same as on the command line. It makes sure that the pager's output matches the raw diff exactly, which is important for git or lazygit to do their job.

Here's a very preliminary draft PR if you want to play with it: #4332. See the PR description for what's missing.

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

Successfully merging a pull request may close this issue.

2 participants