diff --git a/pkg/gui/types/ref.go b/pkg/commands/models/ref.go similarity index 68% rename from pkg/gui/types/ref.go rename to pkg/commands/models/ref.go index 18fc7e998..6ef94ee6d 100644 --- a/pkg/gui/types/ref.go +++ b/pkg/commands/models/ref.go @@ -1,4 +1,4 @@ -package types +package models type Ref interface { FullRefName() string @@ -7,8 +7,3 @@ type Ref interface { ParentRefName() string Description() string } - -type RefRange struct { - From Ref - To Ref -} diff --git a/pkg/gui/context/branches_context.go b/pkg/gui/context/branches_context.go index 9e30e36cc..d73961275 100644 --- a/pkg/gui/context/branches_context.go +++ b/pkg/gui/context/branches_context.go @@ -59,7 +59,7 @@ func NewBranchesContext(c *ContextCommon) *BranchesContext { return self } -func (self *BranchesContext) GetSelectedRef() types.Ref { +func (self *BranchesContext) GetSelectedRef() models.Ref { branch := self.GetSelected() if branch == nil { return nil diff --git a/pkg/gui/context/commit_files_context.go b/pkg/gui/context/commit_files_context.go index d0a5b9f7e..52807faa9 100644 --- a/pkg/gui/context/commit_files_context.go +++ b/pkg/gui/context/commit_files_context.go @@ -96,7 +96,7 @@ func (self *CommitFilesContext) ModelSearchResults(searchStr string, caseSensiti return nil } -func (self *CommitFilesContext) ReInit(ref types.Ref, refRange *types.RefRange) { +func (self *CommitFilesContext) ReInit(ref models.Ref, refRange *types.RefRange) { self.SetRef(ref) self.SetRefRange(refRange) if refRange != nil { diff --git a/pkg/gui/context/local_commits_context.go b/pkg/gui/context/local_commits_context.go index c11770986..e873663c3 100644 --- a/pkg/gui/context/local_commits_context.go +++ b/pkg/gui/context/local_commits_context.go @@ -164,7 +164,7 @@ func (self *LocalCommitsContext) CanRebase() bool { return true } -func (self *LocalCommitsContext) GetSelectedRef() types.Ref { +func (self *LocalCommitsContext) GetSelectedRef() models.Ref { commit := self.GetSelected() if commit == nil { return nil diff --git a/pkg/gui/context/reflog_commits_context.go b/pkg/gui/context/reflog_commits_context.go index 518edeefa..1a882bf12 100644 --- a/pkg/gui/context/reflog_commits_context.go +++ b/pkg/gui/context/reflog_commits_context.go @@ -63,7 +63,7 @@ func (self *ReflogCommitsContext) CanRebase() bool { return false } -func (self *ReflogCommitsContext) GetSelectedRef() types.Ref { +func (self *ReflogCommitsContext) GetSelectedRef() models.Ref { commit := self.GetSelected() if commit == nil { return nil diff --git a/pkg/gui/context/remote_branches_context.go b/pkg/gui/context/remote_branches_context.go index 9e9b00eb1..65f156f25 100644 --- a/pkg/gui/context/remote_branches_context.go +++ b/pkg/gui/context/remote_branches_context.go @@ -54,7 +54,7 @@ func NewRemoteBranchesContext( } } -func (self *RemoteBranchesContext) GetSelectedRef() types.Ref { +func (self *RemoteBranchesContext) GetSelectedRef() models.Ref { remoteBranch := self.GetSelected() if remoteBranch == nil { return nil @@ -62,10 +62,10 @@ func (self *RemoteBranchesContext) GetSelectedRef() types.Ref { return remoteBranch } -func (self *RemoteBranchesContext) GetSelectedRefs() ([]types.Ref, int, int) { +func (self *RemoteBranchesContext) GetSelectedRefs() ([]models.Ref, int, int) { items, startIdx, endIdx := self.GetSelectedItems() - refs := lo.Map(items, func(item *models.RemoteBranch, _ int) types.Ref { + refs := lo.Map(items, func(item *models.RemoteBranch, _ int) models.Ref { return item }) diff --git a/pkg/gui/context/stash_context.go b/pkg/gui/context/stash_context.go index 7dc0066d9..2014de9f3 100644 --- a/pkg/gui/context/stash_context.go +++ b/pkg/gui/context/stash_context.go @@ -53,7 +53,7 @@ func (self *StashContext) CanRebase() bool { return false } -func (self *StashContext) GetSelectedRef() types.Ref { +func (self *StashContext) GetSelectedRef() models.Ref { stash := self.GetSelected() if stash == nil { return nil diff --git a/pkg/gui/context/sub_commits_context.go b/pkg/gui/context/sub_commits_context.go index e489511a0..1e084077b 100644 --- a/pkg/gui/context/sub_commits_context.go +++ b/pkg/gui/context/sub_commits_context.go @@ -141,7 +141,7 @@ func NewSubCommitsContext( type SubCommitsViewModel struct { // name of the ref that the sub-commits are shown for - ref types.Ref + ref models.Ref refToShowDivergenceFrom string *ListViewModel[*models.Commit] @@ -149,11 +149,11 @@ type SubCommitsViewModel struct { showBranchHeads bool } -func (self *SubCommitsViewModel) SetRef(ref types.Ref) { +func (self *SubCommitsViewModel) SetRef(ref models.Ref) { self.ref = ref } -func (self *SubCommitsViewModel) GetRef() types.Ref { +func (self *SubCommitsViewModel) GetRef() models.Ref { return self.ref } @@ -177,7 +177,7 @@ func (self *SubCommitsContext) CanRebase() bool { return false } -func (self *SubCommitsContext) GetSelectedRef() types.Ref { +func (self *SubCommitsContext) GetSelectedRef() models.Ref { commit := self.GetSelected() if commit == nil { return nil diff --git a/pkg/gui/context/tags_context.go b/pkg/gui/context/tags_context.go index c77a5292a..0b98b146a 100644 --- a/pkg/gui/context/tags_context.go +++ b/pkg/gui/context/tags_context.go @@ -52,7 +52,7 @@ func NewTagsContext( } } -func (self *TagsContext) GetSelectedRef() types.Ref { +func (self *TagsContext) GetSelectedRef() models.Ref { tag := self.GetSelected() if tag == nil { return nil diff --git a/pkg/gui/controllers/helpers/diff_helper.go b/pkg/gui/controllers/helpers/diff_helper.go index 1fd73081a..668ee916a 100644 --- a/pkg/gui/controllers/helpers/diff_helper.go +++ b/pkg/gui/controllers/helpers/diff_helper.go @@ -174,7 +174,7 @@ func (self *DiffHelper) IgnoringWhitespaceSubTitle() string { return "" } -func (self *DiffHelper) OpenDiffToolForRef(selectedRef types.Ref) error { +func (self *DiffHelper) OpenDiffToolForRef(selectedRef models.Ref) error { to := selectedRef.RefName() from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff("") _, err := self.c.RunSubprocess(self.c.Git().Diff.OpenDiffToolCmdObj( diff --git a/pkg/gui/controllers/helpers/sub_commits_helper.go b/pkg/gui/controllers/helpers/sub_commits_helper.go index e61c4fee6..c9561a918 100644 --- a/pkg/gui/controllers/helpers/sub_commits_helper.go +++ b/pkg/gui/controllers/helpers/sub_commits_helper.go @@ -24,7 +24,7 @@ func NewSubCommitsHelper( } type ViewSubCommitsOpts struct { - Ref types.Ref + Ref models.Ref RefToShowDivergenceFrom string TitleRef string Context types.Context diff --git a/pkg/gui/controllers/switch_to_diff_files_controller.go b/pkg/gui/controllers/switch_to_diff_files_controller.go index 387da2427..f704f8bd4 100644 --- a/pkg/gui/controllers/switch_to_diff_files_controller.go +++ b/pkg/gui/controllers/switch_to_diff_files_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -11,7 +12,7 @@ var _ types.IController = &SwitchToDiffFilesController{} type CanSwitchToDiffFiles interface { types.IListContext CanRebase() bool - GetSelectedRef() types.Ref + GetSelectedRef() models.Ref GetSelectedRefRangeForDiffFiles() *types.RefRange } diff --git a/pkg/gui/controllers/switch_to_sub_commits_controller.go b/pkg/gui/controllers/switch_to_sub_commits_controller.go index 3df7ddee8..9257e33d3 100644 --- a/pkg/gui/controllers/switch_to_sub_commits_controller.go +++ b/pkg/gui/controllers/switch_to_sub_commits_controller.go @@ -1,6 +1,7 @@ package controllers import ( + "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/controllers/helpers" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -9,7 +10,7 @@ var _ types.IController = &SwitchToSubCommitsController{} type CanSwitchToSubCommits interface { types.IListContext - GetSelectedRef() types.Ref + GetSelectedRef() models.Ref ShowBranchHeadsInSubCommits() bool } @@ -17,7 +18,7 @@ type CanSwitchToSubCommits interface { // but an attribute on it i.e. the ref of an item. type SwitchToSubCommitsController struct { baseController - *ListControllerTrait[types.Ref] + *ListControllerTrait[models.Ref] c *ControllerCommon context CanSwitchToSubCommits } @@ -32,7 +33,7 @@ func NewSwitchToSubCommitsController( c, context, context.GetSelectedRef, - func() ([]types.Ref, int, int) { + func() ([]models.Ref, int, int) { panic("Not implemented") }, ), diff --git a/pkg/gui/filetree/commit_file_tree_view_model.go b/pkg/gui/filetree/commit_file_tree_view_model.go index c857a6a62..82c478a3e 100644 --- a/pkg/gui/filetree/commit_file_tree_view_model.go +++ b/pkg/gui/filetree/commit_file_tree_view_model.go @@ -15,8 +15,8 @@ type ICommitFileTreeViewModel interface { ICommitFileTree types.IListCursor - GetRef() types.Ref - SetRef(types.Ref) + GetRef() models.Ref + SetRef(models.Ref) GetRefRange() *types.RefRange // can be nil, in which case GetRef should be used SetRefRange(*types.RefRange) // should be set to nil when selection is not a range GetCanRebase() bool @@ -30,7 +30,7 @@ type CommitFileTreeViewModel struct { // this is e.g. the commit for which we're viewing the files, if there is no // range selection, or if the range selection can't be used for some reason - ref types.Ref + ref models.Ref // this is a commit range for which we're viewing the files. Can be nil, in // which case ref is used. @@ -55,11 +55,11 @@ func NewCommitFileTreeViewModel(getFiles func() []*models.CommitFile, common *co } } -func (self *CommitFileTreeViewModel) GetRef() types.Ref { +func (self *CommitFileTreeViewModel) GetRef() models.Ref { return self.ref } -func (self *CommitFileTreeViewModel) SetRef(ref types.Ref) { +func (self *CommitFileTreeViewModel) SetRef(ref models.Ref) { self.ref = ref } diff --git a/pkg/gui/types/ref_range.go b/pkg/gui/types/ref_range.go new file mode 100644 index 000000000..437b1aafd --- /dev/null +++ b/pkg/gui/types/ref_range.go @@ -0,0 +1,8 @@ +package types + +import "github.com/jesseduffield/lazygit/pkg/commands/models" + +type RefRange struct { + From models.Ref + To models.Ref +}