Repository navigation
Show errors for unresolvable diff lines - #6100
Merged
Merged
Conversation
Base automatically changed from
fix-staging-with-mnemonic-diff-prefixes
to
master
October 10, 2026 11:03
The focused diff actions look up the file of a selected line in different places. In the files panel, staging and discarding do it per file while applying the patches, and editing a hunk does it for the first line. For a commit's diff, adding lines to a custom patch or discarding them from the commit does it only after the confirmation prompt and after a new patch has been started. The next commits report a line whose file can't be found as an error. For that, the lookup has to happen once, before we log an action, ask for confirmation or start a patch. So let diffLineSelection group the selected lines by their file, in the order the diff shows the files, and do the same for a commit's diff in selectionByFile. A line whose file can't be found is still skipped, as before. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
If git fails to list the files of the diff that a custom patch is built from, we carry on as if the diff had no files. Then we don't know which files were renamed, added or deleted, and build the patch from the wrong lines or without the file's creation or deletion. Return the error instead, so that the user sees it. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When staging, discarding or taking lines out of a custom patch spans several files, we read the diff of a file and apply its patch before we look at the next file. The next commits report an error if the selected lines of a file can't be found. Without this change, the files before it would already be acted on by then. So find the lines in every file first, and only then apply anything. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
If the path in the diff header of a selected line doesn't name a file of the files panel, staging or discarding the line does nothing. The command log shows "Apply patch", but nothing else happens, so the user has nothing to go on when reporting it. Adding a line of a commit's diff to a custom patch fails in the same silent way if the path doesn't name a file of that diff. A diff renderer that names files differently can cause this, and so can a bug in how we read the path, like the one we had with diff.mnemonicPrefix. Show an error that names the path instead, and do nothing else. If a selection spans several files, don't act on the files we did find, because that would do only part of what the user asked for. Do the same for opening a line of a diff in its pull request. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
When we stage, discard or edit lines of the working tree's diff, we read the file's diff again and look for the selected lines in it. If none of them are there, nothing happens. The same goes for adding lines of a commit's diff to a custom patch, or taking lines out of it. This can happen if the file changed since its diff was shown, or if we read the line numbers out of the diff on screen wrongly. Show an error that names the file instead. As with a file that can't be found, don't act on any file if the lines of one are missing. Unlike the file check, this one happens after a new custom patch has been started. If the error leaves that patch without any lines, reset it, as we do when the last line is taken out of a patch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Discarding lines from a commit's diff rewrites the commit with a rebase. For this we look up the commit among the commits of the current branch. If it isn't there, pressing the key does nothing. The disabled reason only allows discarding in a diff of the commits panel, so this shouldn't happen. If it does, the user should see it. Show an error that names the commit instead. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
stefanhaller
force-pushed
the
show-errors-for-unresolvable-diff-lines
branch
from
October 10, 2026 11:04
703e24a to
2a3883f
Compare
stefanhaller
enabled auto-merge
October 10, 2026 11:05
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
If lazygit can't work out what diff lines it is supposed to act on when staging a hunk (for example because of bugs like the one in #6099, or maybe because of a misbehaving OSC-1717 diff renderer), it used to do nothing and silently ignore the error. Now it shows an error popup to the user in such a case, so that they can report the bug more easily.