Skip to content

Commit a1aeedd

Browse files
committed
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.
1 parent e716617 commit a1aeedd

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

pkg/gui/controllers/helpers/diff_helper.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,20 @@ func (self *DiffHelper) GetUpdateTaskForRenderingCommitsDiff(commit *models.Comm
5757
from, to := refRange.From, refRange.To
5858
args := []string{from.ParentRefName(), to.RefName(), "--stat", "-p"}
5959
args = append(args, "--")
60-
if path := self.c.Modes().Filtering.GetPath(); path != "" {
61-
args = append(args, path)
60+
if filterPath := self.c.Modes().Filtering.GetPath(); filterPath != "" {
61+
// If both refs are commits, filter by the union of their paths. This is useful for
62+
// example when diffing a range of commits in filter-by-path mode across a rename.
63+
fromCommit, ok1 := from.(*models.Commit)
64+
toCommit, ok2 := to.(*models.Commit)
65+
if ok1 && ok2 {
66+
paths := append(self.FilterPathsForCommit(fromCommit), self.FilterPathsForCommit(toCommit)...)
67+
args = append(args, lo.Uniq(paths)...)
68+
} else {
69+
// If either ref is not a commit (which is possible in sticky diff mode, when
70+
// diffing against a branch or tag), we just filter by the filter path; that's the
71+
// best we can do in this case.
72+
args = append(args, filterPath)
73+
}
6274
}
6375
cmdObj := self.c.Git().Diff.DiffCmdObj(args)
6476
prefix := style.FgYellow.Sprintf("%s %s-%s\n\n", self.c.Tr.ShowingDiffForRange, from.ShortRefName(), to.ShortRefName())

pkg/integration/tests/filter_by_path/show_diffs_for_renamed_file.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ var ShowDiffsForRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{
113113
Press(keys.Universal.RangeSelectUp)
114114

115115
t.Views().Main().ContainsLines(
116-
/* EXPECTED:
117116
Contains("Showing diff for range"),
118117
Equals(""),
119118
Equals(" oldFile => newFile | 2 +-"),
@@ -131,19 +130,6 @@ var ShowDiffsForRenamedFile = NewIntegrationTest(NewIntegrationTestArgs{
131130
Equals("+y"),
132131
Equals(" b"),
133132
Equals(" c"),
134-
ACTUAL: */
135-
Equals(" newFile | 3 +++"),
136-
Equals(" 1 file changed, 3 insertions(+)"),
137-
Equals(""),
138-
Equals("diff --git a/newFile b/newFile"),
139-
Equals("new file mode 100644"),
140-
Contains("index"),
141-
Equals("--- /dev/null"),
142-
Equals("+++ b/newFile"),
143-
Equals("@@ -0,0 +1,3 @@"),
144-
Equals("+y"),
145-
Equals("+b"),
146-
Equals("+c"),
147133
)
148134
},
149135
})

0 commit comments

Comments
 (0)