diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index 9689df29b..4ad7334ef 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -85,10 +85,16 @@ func (self *CommitFilesContext) RefForAdjustingLineNumberInDiff() string { } func (self *CommitFilesContext) GetFromAndToForDiff() (string, string) { - if refs := self.GetRefRange(); refs != nil { - return refs.From.ParentRefName(), refs.To.RefName() + return FromAndToForDiff(self.GetRef(), self.GetRefRange()) +} + +// FromAndToForDiff gives the two ends to diff for a ref, or for a range of them: a +// range runs from the parent of its first ref to its last, a single ref from its own +// parent to itself. +func FromAndToForDiff(ref models.Ref, refRange *types.RefRange) (string, string) { + if refRange != nil { + return refRange.From.ParentRefName(), refRange.To.RefName() } - ref := self.GetRef() return ref.ParentRefName(), ref.RefName() }