mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-15 00:15:32 +02:00
Extract a SubCommitsHelper from SwitchToSubCommitsController
We want to use it from BranchesController too.
This commit is contained in:
@ -1,10 +1,8 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/git_commands"
|
||||
"github.com/jesseduffield/lazygit/pkg/commands/models"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers"
|
||||
"github.com/jesseduffield/lazygit/pkg/gui/types"
|
||||
"github.com/jesseduffield/lazygit/pkg/utils"
|
||||
)
|
||||
|
||||
var _ types.IController = &SwitchToSubCommitsController{}
|
||||
@ -19,20 +17,16 @@ type SwitchToSubCommitsController struct {
|
||||
baseController
|
||||
c *ControllerCommon
|
||||
context CanSwitchToSubCommits
|
||||
|
||||
setSubCommits func([]*models.Commit)
|
||||
}
|
||||
|
||||
func NewSwitchToSubCommitsController(
|
||||
controllerCommon *ControllerCommon,
|
||||
setSubCommits func([]*models.Commit),
|
||||
context CanSwitchToSubCommits,
|
||||
) *SwitchToSubCommitsController {
|
||||
return &SwitchToSubCommitsController{
|
||||
baseController: baseController{},
|
||||
c: controllerCommon,
|
||||
context: context,
|
||||
setSubCommits: setSubCommits,
|
||||
}
|
||||
}
|
||||
|
||||
@ -58,40 +52,11 @@ func (self *SwitchToSubCommitsController) viewCommits() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// need to populate my sub commits
|
||||
commits, err := self.c.Git().Loaders.CommitLoader.GetCommits(
|
||||
git_commands.GetCommitsOptions{
|
||||
Limit: true,
|
||||
FilterPath: self.c.Modes().Filtering.GetPath(),
|
||||
IncludeRebaseCommits: false,
|
||||
RefName: ref.FullRefName(),
|
||||
RefForPushedStatus: ref.FullRefName(),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
self.setSubCommits(commits)
|
||||
self.c.Helpers().Refresh.RefreshAuthors(commits)
|
||||
|
||||
subCommitsContext := self.c.Contexts().SubCommits
|
||||
subCommitsContext.SetSelectedLineIdx(0)
|
||||
subCommitsContext.SetParentContext(self.context)
|
||||
subCommitsContext.SetWindowName(self.context.GetWindowName())
|
||||
subCommitsContext.SetTitleRef(utils.TruncateWithEllipsis(ref.RefName(), 50))
|
||||
subCommitsContext.SetRef(ref)
|
||||
subCommitsContext.SetLimitCommits(true)
|
||||
subCommitsContext.SetShowBranchHeads(self.context.ShowBranchHeadsInSubCommits())
|
||||
subCommitsContext.ClearSearchString()
|
||||
subCommitsContext.GetView().ClearSearch()
|
||||
|
||||
err = self.c.PostRefreshUpdate(self.c.Contexts().SubCommits)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return self.c.PushContext(self.c.Contexts().SubCommits)
|
||||
return self.c.Helpers().SubCommits.ViewSubCommits(helpers.ViewSubCommitsOpts{
|
||||
Ref: ref,
|
||||
Context: self.context,
|
||||
ShowBranchHeads: self.context.ShowBranchHeadsInSubCommits(),
|
||||
})
|
||||
}
|
||||
|
||||
func (self *SwitchToSubCommitsController) Context() types.Context {
|
||||
|
Reference in New Issue
Block a user