1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-08-06 22:33:07 +02:00

Fix showing range diff across a rename when filtering by path

We need to pass the union of filter paths at both ends of the range.
This commit is contained in:
Stefan Haller
2025-07-17 20:52:46 +02:00
parent e716617a82
commit a1aeedd5d5
2 changed files with 14 additions and 16 deletions

View File

@ -57,8 +57,20 @@ func (self *DiffHelper) GetUpdateTaskForRenderingCommitsDiff(commit *models.Comm
from, to := refRange.From, refRange.To from, to := refRange.From, refRange.To
args := []string{from.ParentRefName(), to.RefName(), "--stat", "-p"} args := []string{from.ParentRefName(), to.RefName(), "--stat", "-p"}
args = append(args, "--") args = append(args, "--")
if path := self.c.Modes().Filtering.GetPath(); path != "" { if filterPath := self.c.Modes().Filtering.GetPath(); filterPath != "" {
args = append(args, path) // If both refs are commits, filter by the union of their paths. This is useful for
// example when diffing a range of commits in filter-by-path mode across a rename.
fromCommit, ok1 := from.(*models.Commit)
toCommit, ok2 := to.(*models.Commit)
if ok1 && ok2 {
paths := append(self.FilterPathsForCommit(fromCommit), self.FilterPathsForCommit(toCommit)...)
args = append(args, lo.Uniq(paths)...)
} else {
// If either ref is not a commit (which is possible in sticky diff mode, when
// diffing against a branch or tag), we just filter by the filter path; that's the
// best we can do in this case.
args = append(args, filterPath)
}
} }
cmdObj := self.c.Git().Diff.DiffCmdObj(args) cmdObj := self.c.Git().Diff.DiffCmdObj(args)
prefix := style.FgYellow.Sprintf("%s %s-%s\n\n", self.c.Tr.ShowingDiffForRange, from.ShortRefName(), to.ShortRefName()) prefix := style.FgYellow.Sprintf("%s %s-%s\n\n", self.c.Tr.ShowingDiffForRange, from.ShortRefName(), to.ShortRefName())

View File

@ -113,7 +113,6 @@ var ShowDiffsForRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{
Press(keys.Universal.RangeSelectUp) Press(keys.Universal.RangeSelectUp)
t.Views().Main().ContainsLines( t.Views().Main().ContainsLines(
/* EXPECTED:
Contains("Showing diff for range"), Contains("Showing diff for range"),
Equals(""), Equals(""),
Equals(" oldFile => newFile | 2 +-"), Equals(" oldFile => newFile | 2 +-"),
@ -131,19 +130,6 @@ var ShowDiffsForRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{
Equals("+y"), Equals("+y"),
Equals(" b"), Equals(" b"),
Equals(" c"), Equals(" c"),
ACTUAL: */
Equals(" newFile | 3 +++"),
Equals(" 1 file changed, 3 insertions(+)"),
Equals(""),
Equals("diff --git a/newFile b/newFile"),
Equals("new file mode 100644"),
Contains("index"),
Equals("--- /dev/null"),
Equals("+++ b/newFile"),
Equals("@@ -0,0 +1,3 @@"),
Equals("+y"),
Equals("+b"),
Equals("+c"),
) )
}, },
}) })