diff --git a/pkg/gui/controllers.go b/pkg/gui/controllers.go index b0520c975..fa20b119f 100644 --- a/pkg/gui/controllers.go +++ b/pkg/gui/controllers.go @@ -15,55 +15,49 @@ func (gui *Gui) resetControllers() { helperCommon := gui.c osCommand := gui.os model := gui.State.Model - refsHelper := helpers.NewRefsHelper( - helperCommon, - gui.git, - gui.State.Contexts, - model, - ) + refsHelper := helpers.NewRefsHelper(helperCommon) - rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, gui.State.Contexts, gui.git, refsHelper) - suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon, model, gui.State.Contexts) + rebaseHelper := helpers.NewMergeAndRebaseHelper(helperCommon, refsHelper) + suggestionsHelper := helpers.NewSuggestionsHelper(helperCommon) setCommitMessage := gui.getSetTextareaTextFn(func() *gocui.View { return gui.Views.CommitMessage }) getSavedCommitMessage := func() string { return gui.State.savedCommitMessage } - gpgHelper := helpers.NewGpgHelper(helperCommon, gui.os, gui.git) + gpgHelper := helpers.NewGpgHelper(helperCommon) viewHelper := helpers.NewViewHelper(helperCommon, gui.State.Contexts) recordDirectoryHelper := helpers.NewRecordDirectoryHelper(helperCommon) - patchBuildingHelper := helpers.NewPatchBuildingHelper(helperCommon, gui.git, gui.State.Contexts) - stagingHelper := helpers.NewStagingHelper(helperCommon, gui.git, gui.State.Contexts) - mergeConflictsHelper := helpers.NewMergeConflictsHelper(helperCommon, gui.State.Contexts, gui.git) - refreshHelper := helpers.NewRefreshHelper(helperCommon, gui.State.Contexts, gui.git, refsHelper, rebaseHelper, patchBuildingHelper, stagingHelper, mergeConflictsHelper, gui.fileWatcher) + patchBuildingHelper := helpers.NewPatchBuildingHelper(helperCommon) + stagingHelper := helpers.NewStagingHelper(helperCommon) + mergeConflictsHelper := helpers.NewMergeConflictsHelper(helperCommon) + refreshHelper := helpers.NewRefreshHelper(helperCommon, refsHelper, rebaseHelper, patchBuildingHelper, stagingHelper, mergeConflictsHelper, gui.fileWatcher) gui.helpers = &helpers.Helpers{ Refs: refsHelper, - Host: helpers.NewHostHelper(helperCommon, gui.git), + Host: helpers.NewHostHelper(helperCommon), PatchBuilding: patchBuildingHelper, Staging: stagingHelper, Bisect: helpers.NewBisectHelper(helperCommon), Suggestions: suggestionsHelper, - Files: helpers.NewFilesHelper(helperCommon, gui.git, osCommand), - WorkingTree: helpers.NewWorkingTreeHelper(helperCommon, gui.git, gui.State.Contexts, refsHelper, model, setCommitMessage, getSavedCommitMessage), - Tags: helpers.NewTagsHelper(helperCommon, gui.git), + Files: helpers.NewFilesHelper(helperCommon), + WorkingTree: helpers.NewWorkingTreeHelper(helperCommon, refsHelper, setCommitMessage, getSavedCommitMessage), + Tags: helpers.NewTagsHelper(helperCommon), GPG: gpgHelper, MergeAndRebase: rebaseHelper, MergeConflicts: mergeConflictsHelper, CherryPick: helpers.NewCherryPickHelper( helperCommon, - gui.State.Contexts, rebaseHelper, ), - Upstream: helpers.NewUpstreamHelper(helperCommon, model, suggestionsHelper.GetRemoteBranchesSuggestionsFunc), - AmendHelper: helpers.NewAmendHelper(helperCommon, gui.git, gpgHelper), + Upstream: helpers.NewUpstreamHelper(helperCommon, suggestionsHelper.GetRemoteBranchesSuggestionsFunc), + AmendHelper: helpers.NewAmendHelper(helperCommon, gpgHelper), Snake: helpers.NewSnakeHelper(helperCommon), Diff: helpers.NewDiffHelper(helperCommon), Repos: helpers.NewRecentReposHelper(helperCommon, recordDirectoryHelper, gui.onNewRepo), RecordDirectory: recordDirectoryHelper, Update: helpers.NewUpdateHelper(helperCommon, gui.Updater), - Window: helpers.NewWindowHelper(helperCommon, viewHelper, gui.State.Contexts), + Window: helpers.NewWindowHelper(helperCommon, viewHelper), View: viewHelper, Refresh: refreshHelper, - Confirmation: helpers.NewConfirmationHelper(helperCommon, gui.State.Contexts), + Confirmation: helpers.NewConfirmationHelper(helperCommon), } gui.CustomCommandsClient = custom_commands.NewClient( diff --git a/pkg/gui/controllers/helpers/amend_helper.go b/pkg/gui/controllers/helpers/amend_helper.go index 29570d635..0e5216f83 100644 --- a/pkg/gui/controllers/helpers/amend_helper.go +++ b/pkg/gui/controllers/helpers/amend_helper.go @@ -1,24 +1,20 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/gui/types" ) type AmendHelper struct { - c *types.HelperCommon - git *commands.GitCommand + c *HelperCommon gpg *GpgHelper } func NewAmendHelper( - c *types.HelperCommon, - git *commands.GitCommand, + c *HelperCommon, gpg *GpgHelper, ) *AmendHelper { return &AmendHelper{ c: c, - git: git, gpg: gpg, } } @@ -28,7 +24,7 @@ func (self *AmendHelper) AmendHead() error { Title: self.c.Tr.AmendLastCommitTitle, Prompt: self.c.Tr.SureToAmend, HandleConfirm: func() error { - cmdObj := self.git.Commit.AmendHeadCmdObj() + cmdObj := self.c.Git().Commit.AmendHeadCmdObj() self.c.LogAction(self.c.Tr.Actions.AmendCommit) return self.gpg.WithGpgHandling(cmdObj, self.c.Tr.AmendingStatus, nil) }, diff --git a/pkg/gui/controllers/helpers/cherry_pick_helper.go b/pkg/gui/controllers/helpers/cherry_pick_helper.go index 695a726ae..2c9b7c7c9 100644 --- a/pkg/gui/controllers/helpers/cherry_pick_helper.go +++ b/pkg/gui/controllers/helpers/cherry_pick_helper.go @@ -2,7 +2,6 @@ package helpers import ( "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/modes/cherrypicking" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -10,8 +9,6 @@ import ( type CherryPickHelper struct { c *HelperCommon - contexts *context.ContextTree - rebaseHelper *MergeAndRebaseHelper } @@ -20,12 +17,10 @@ type CherryPickHelper struct { func NewCherryPickHelper( c *HelperCommon, - contexts *context.ContextTree, rebaseHelper *MergeAndRebaseHelper, ) *CherryPickHelper { return &CherryPickHelper{ c: c, - contexts: contexts, rebaseHelper: rebaseHelper, } } @@ -111,9 +106,9 @@ func (self *CherryPickHelper) resetIfNecessary(context types.Context) error { func (self *CherryPickHelper) rerender() error { for _, context := range []types.Context{ - self.contexts.LocalCommits, - self.contexts.ReflogCommits, - self.contexts.SubCommits, + self.c.Contexts().LocalCommits, + self.c.Contexts().ReflogCommits, + self.c.Contexts().SubCommits, } { if err := self.c.PostRefreshUpdate(context); err != nil { return err diff --git a/pkg/gui/controllers/helpers/confirmation_helper.go b/pkg/gui/controllers/helpers/confirmation_helper.go index d7ccb151a..e6e3deeef 100644 --- a/pkg/gui/controllers/helpers/confirmation_helper.go +++ b/pkg/gui/controllers/helpers/confirmation_helper.go @@ -6,7 +6,6 @@ import ( "strings" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" @@ -15,17 +14,12 @@ import ( ) type ConfirmationHelper struct { - c *HelperCommon - contexts *context.ContextTree + c *HelperCommon } -func NewConfirmationHelper( - c *HelperCommon, - contexts *context.ContextTree, -) *ConfirmationHelper { +func NewConfirmationHelper(c *HelperCommon) *ConfirmationHelper { return &ConfirmationHelper{ - c: c, - contexts: contexts, + c: c, } } @@ -133,7 +127,7 @@ func (self *ConfirmationHelper) prepareConfirmationPanel( self.c.Views().Confirmation.Mask = runeForMask(opts.Mask) _ = self.c.Views().Confirmation.SetOrigin(0, 0) - suggestionsContext := self.contexts.Suggestions + suggestionsContext := self.c.Contexts().Suggestions suggestionsContext.State.FindSuggestions = opts.FindSuggestionsFunc if opts.FindSuggestionsFunc != nil { suggestionsView := self.c.Views().Suggestions @@ -210,7 +204,7 @@ func (self *ConfirmationHelper) CreatePopupPanel(ctx goContext.Context, opts typ self.c.State().GetRepoState().SetCurrentPopupOpts(&opts) - return self.c.PushContext(self.contexts.Confirmation) + return self.c.PushContext(self.c.Contexts().Confirmation) } func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts types.CreatePopupPanelOpts) error { @@ -229,24 +223,24 @@ func (self *ConfirmationHelper) setKeyBindings(cancel goContext.CancelFunc, opts onClose := self.wrappedConfirmationFunction(cancel, opts.HandleClose) - self.contexts.Confirmation.State.OnConfirm = onConfirm - self.contexts.Confirmation.State.OnClose = onClose - self.contexts.Suggestions.State.OnConfirm = onSuggestionConfirm - self.contexts.Suggestions.State.OnClose = onClose + self.c.Contexts().Confirmation.State.OnConfirm = onConfirm + self.c.Contexts().Confirmation.State.OnClose = onClose + self.c.Contexts().Suggestions.State.OnConfirm = onSuggestionConfirm + self.c.Contexts().Suggestions.State.OnClose = onClose return nil } func (self *ConfirmationHelper) clearConfirmationViewKeyBindings() { noop := func() error { return nil } - self.contexts.Confirmation.State.OnConfirm = noop - self.contexts.Confirmation.State.OnClose = noop - self.contexts.Suggestions.State.OnConfirm = noop - self.contexts.Suggestions.State.OnClose = noop + self.c.Contexts().Confirmation.State.OnConfirm = noop + self.c.Contexts().Confirmation.State.OnClose = noop + self.c.Contexts().Suggestions.State.OnConfirm = noop + self.c.Contexts().Suggestions.State.OnClose = noop } func (self *ConfirmationHelper) getSelectedSuggestionValue() string { - selectedSuggestion := self.contexts.Suggestions.GetSelected() + selectedSuggestion := self.c.Contexts().Suggestions.GetSelected() if selectedSuggestion != nil { return selectedSuggestion.Value @@ -300,7 +294,7 @@ func (self *ConfirmationHelper) ResizePopupPanel(v *gocui.View, content string) } func (self *ConfirmationHelper) resizeMenu() { - itemCount := self.contexts.Menu.GetList().Len() + itemCount := self.c.Contexts().Menu.GetList().Len() offset := 3 panelWidth := self.getConfirmationPanelWidth() x0, y0, x1, y1 := self.getConfirmationPanelDimensionsForContentHeight(panelWidth, itemCount+offset) @@ -308,7 +302,7 @@ func (self *ConfirmationHelper) resizeMenu() { _, _ = self.c.GocuiGui().SetView(self.c.Views().Menu.Name(), x0, y0, x1, menuBottom, 0) tooltipTop := menuBottom + 1 - tooltipHeight := getMessageHeight(true, self.contexts.Menu.GetSelected().Tooltip, panelWidth) + 2 // plus 2 for the frame + tooltipHeight := getMessageHeight(true, self.c.Contexts().Menu.GetSelected().Tooltip, panelWidth) + 2 // plus 2 for the frame _, _ = self.c.GocuiGui().SetView(self.c.Views().Tooltip.Name(), x0, tooltipTop, x1, tooltipTop+tooltipHeight-1, 0) } diff --git a/pkg/gui/controllers/helpers/files_helper.go b/pkg/gui/controllers/helpers/files_helper.go index 9893123cb..1baa0191b 100644 --- a/pkg/gui/controllers/helpers/files_helper.go +++ b/pkg/gui/controllers/helpers/files_helper.go @@ -1,10 +1,5 @@ package helpers -import ( - "github.com/jesseduffield/lazygit/pkg/commands" - "github.com/jesseduffield/lazygit/pkg/commands/oscommands" -) - type IFilesHelper interface { EditFile(filename string) error EditFileAtLine(filename string, lineNumber int) error @@ -12,37 +7,29 @@ type IFilesHelper interface { } type FilesHelper struct { - c *HelperCommon - git *commands.GitCommand - os *oscommands.OSCommand + c *HelperCommon } -func NewFilesHelper( - c *HelperCommon, - git *commands.GitCommand, - os *oscommands.OSCommand, -) *FilesHelper { +func NewFilesHelper(c *HelperCommon) *FilesHelper { return &FilesHelper{ - c: c, - git: git, - os: os, + c: c, } } var _ IFilesHelper = &FilesHelper{} func (self *FilesHelper) EditFile(filename string) error { - cmdStr, editInTerminal := self.git.File.GetEditCmdStr(filename) + cmdStr, editInTerminal := self.c.Git().File.GetEditCmdStr(filename) return self.callEditor(cmdStr, editInTerminal) } func (self *FilesHelper) EditFileAtLine(filename string, lineNumber int) error { - cmdStr, editInTerminal := self.git.File.GetEditAtLineCmdStr(filename, lineNumber) + cmdStr, editInTerminal := self.c.Git().File.GetEditAtLineCmdStr(filename, lineNumber) return self.callEditor(cmdStr, editInTerminal) } func (self *FilesHelper) EditFileAtLineAndWait(filename string, lineNumber int) error { - cmdStr := self.git.File.GetEditAtLineAndWaitCmdStr(filename, lineNumber) + cmdStr := self.c.Git().File.GetEditAtLineAndWaitCmdStr(filename, lineNumber) // Always suspend, regardless of the value of the editInTerminal config, // since we want to prevent interacting with the UI until the editor @@ -53,16 +40,16 @@ func (self *FilesHelper) EditFileAtLineAndWait(filename string, lineNumber int) func (self *FilesHelper) callEditor(cmdStr string, editInTerminal bool) error { if editInTerminal { return self.c.RunSubprocessAndRefresh( - self.os.Cmd.NewShell(cmdStr), + self.c.OS().Cmd.NewShell(cmdStr), ) } - return self.os.Cmd.NewShell(cmdStr).Run() + return self.c.OS().Cmd.NewShell(cmdStr).Run() } func (self *FilesHelper) OpenFile(filename string) error { self.c.LogAction(self.c.Tr.Actions.OpenFile) - if err := self.os.OpenFile(filename); err != nil { + if err := self.c.OS().OpenFile(filename); err != nil { return self.c.Error(err) } return nil diff --git a/pkg/gui/controllers/helpers/gpg_helper.go b/pkg/gui/controllers/helpers/gpg_helper.go index 0249c560f..0cefc4208 100644 --- a/pkg/gui/controllers/helpers/gpg_helper.go +++ b/pkg/gui/controllers/helpers/gpg_helper.go @@ -3,26 +3,17 @@ package helpers import ( "fmt" - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" "github.com/jesseduffield/lazygit/pkg/gui/types" ) type GpgHelper struct { - c *HelperCommon - os *oscommands.OSCommand - git *commands.GitCommand + c *HelperCommon } -func NewGpgHelper( - c *HelperCommon, - os *oscommands.OSCommand, - git *commands.GitCommand, -) *GpgHelper { +func NewGpgHelper(c *HelperCommon) *GpgHelper { return &GpgHelper{ - c: c, - os: os, - git: git, + c: c, } } @@ -32,9 +23,9 @@ func NewGpgHelper( // we don't need to see a loading status if we're in a subprocess. // TODO: we shouldn't need to use a shell here, but looks like that NewShell function contains some windows specific quoting stuff. We should centralise that. func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error { - useSubprocess := self.git.Config.UsingGpg() + useSubprocess := self.c.Git().Config.UsingGpg() if useSubprocess { - success, err := self.c.RunSubprocess(self.os.Cmd.NewShell(cmdObj.ToString())) + success, err := self.c.RunSubprocess(self.c.OS().Cmd.NewShell(cmdObj.ToString())) if success && onSuccess != nil { if err := onSuccess(); err != nil { return err @@ -51,7 +42,7 @@ func (self *GpgHelper) WithGpgHandling(cmdObj oscommands.ICmdObj, waitingStatus } func (self *GpgHelper) runAndStream(cmdObj oscommands.ICmdObj, waitingStatus string, onSuccess func() error) error { - cmdObj = self.os.Cmd.NewShell(cmdObj.ToString()) + cmdObj = self.c.OS().Cmd.NewShell(cmdObj.ToString()) return self.c.WithWaitingStatus(waitingStatus, func() error { if err := cmdObj.StreamOutput().Run(); err != nil { diff --git a/pkg/gui/controllers/helpers/host_helper.go b/pkg/gui/controllers/helpers/host_helper.go index b11bc32c2..06102cc13 100644 --- a/pkg/gui/controllers/helpers/host_helper.go +++ b/pkg/gui/controllers/helpers/host_helper.go @@ -1,7 +1,6 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/hosting_service" ) @@ -13,17 +12,14 @@ type IHostHelper interface { } type HostHelper struct { - c *HelperCommon - git *commands.GitCommand + c *HelperCommon } func NewHostHelper( c *HelperCommon, - git *commands.GitCommand, ) *HostHelper { return &HostHelper{ - c: c, - git: git, + c: c, } } @@ -39,7 +35,7 @@ func (self *HostHelper) GetCommitURL(commitSha string) (string, error) { // from one invocation to the next. Note however that we're currently caching config // results so we might want to invalidate the cache here if it becomes a problem. func (self *HostHelper) getHostingServiceMgr() *hosting_service.HostingServiceMgr { - remoteUrl := self.git.Config.GetRemoteURL() + remoteUrl := self.c.Git().Config.GetRemoteURL() configServices := self.c.UserConfig.Services return hosting_service.NewHostingServiceMgr(self.c.Log, self.c.Tr, remoteUrl, configServices) } diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 56154e6ad..dfa40e434 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -5,31 +5,23 @@ import ( "strings" "github.com/jesseduffield/generics/slices" - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) type MergeAndRebaseHelper struct { c *HelperCommon - contexts *context.ContextTree - git *commands.GitCommand refsHelper *RefsHelper } func NewMergeAndRebaseHelper( c *HelperCommon, - contexts *context.ContextTree, - git *commands.GitCommand, refsHelper *RefsHelper, ) *MergeAndRebaseHelper { return &MergeAndRebaseHelper{ c: c, - contexts: contexts, - git: git, refsHelper: refsHelper, } } @@ -53,7 +45,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { {option: REBASE_OPTION_ABORT, key: 'a'}, } - if self.git.Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { + if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_REBASING { options = append(options, optionAndKey{ option: REBASE_OPTION_SKIP, key: 's', }) @@ -70,7 +62,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { }) var title string - if self.git.Status.WorkingTreeState() == enums.REBASE_MODE_MERGING { + if self.c.Git().Status.WorkingTreeState() == enums.REBASE_MODE_MERGING { title = self.c.Tr.MergeOptionsTitle } else { title = self.c.Tr.RebaseOptionsTitle @@ -80,7 +72,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { } func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error { - status := self.git.Status.WorkingTreeState() + status := self.c.Git().Status.WorkingTreeState() if status != enums.REBASE_MODE_MERGING && status != enums.REBASE_MODE_REBASING { return self.c.ErrorMsg(self.c.Tr.NotMergingOrRebasing) @@ -104,10 +96,10 @@ func (self *MergeAndRebaseHelper) genericMergeCommand(command string) error { if status == enums.REBASE_MODE_MERGING && command != REBASE_OPTION_ABORT && self.c.UserConfig.Git.Merging.ManualCommit { // TODO: see if we should be calling more of the code from self.Git.Rebase.GenericMergeOrRebaseAction return self.c.RunSubprocessAndRefresh( - self.git.Rebase.GenericMergeOrRebaseActionCmdObj(commandType, command), + self.c.Git().Rebase.GenericMergeOrRebaseActionCmdObj(commandType, command), ) } - result := self.git.Rebase.GenericMergeOrRebaseAction(commandType, command) + result := self.c.Git().Rebase.GenericMergeOrRebaseAction(commandType, command) if err := self.CheckMergeOrRebase(result); err != nil { return err } @@ -150,7 +142,7 @@ func (self *MergeAndRebaseHelper) CheckMergeOrRebase(result error) error { Title: self.c.Tr.FoundConflictsTitle, Prompt: self.c.Tr.FoundConflicts, HandleConfirm: func() error { - return self.c.PushContext(self.contexts.Files) + return self.c.PushContext(self.c.Contexts().Files) }, HandleClose: func() error { return self.genericMergeCommand(REBASE_OPTION_ABORT) @@ -174,7 +166,7 @@ func (self *MergeAndRebaseHelper) AbortMergeOrRebaseWithConfirm() error { } func (self *MergeAndRebaseHelper) workingTreeStateNoun() string { - workingTreeState := self.git.Status.WorkingTreeState() + workingTreeState := self.c.Git().Status.WorkingTreeState() switch workingTreeState { case enums.REBASE_MODE_NONE: return "" @@ -207,7 +199,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { Key: 's', OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.RebaseBranch) - err := self.git.Rebase.RebaseBranch(ref) + err := self.c.Git().Rebase.RebaseBranch(ref) return self.CheckMergeOrRebase(err) }, }, @@ -217,11 +209,11 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { Tooltip: self.c.Tr.InteractiveRebaseTooltip, OnPress: func() error { self.c.LogAction(self.c.Tr.Actions.RebaseBranch) - err := self.git.Rebase.EditRebase(ref) + err := self.c.Git().Rebase.EditRebase(ref) if err = self.CheckMergeOrRebase(err); err != nil { return err } - return self.c.PushContext(self.contexts.LocalCommits) + return self.c.PushContext(self.c.Contexts().LocalCommits) }, }, } @@ -241,7 +233,7 @@ func (self *MergeAndRebaseHelper) RebaseOntoRef(ref string) error { } func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) error { - if self.git.Branch.IsHeadDetached() { + if self.c.Git().Branch.IsHeadDetached() { return self.c.ErrorMsg("Cannot merge branch in detached head state. You might have checked out a commit directly or a remote branch, in which case you should checkout the local branch you want to be on") } checkedOutBranchName := self.refsHelper.GetCheckedOutRef().Name @@ -261,7 +253,7 @@ func (self *MergeAndRebaseHelper) MergeRefIntoCheckedOutBranch(refName string) e Prompt: prompt, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.Merge) - err := self.git.Branch.Merge(refName, git_commands.MergeOpts{}) + err := self.c.Git().Branch.Merge(refName, git_commands.MergeOpts{}) return self.CheckMergeOrRebase(err) }, }) diff --git a/pkg/gui/controllers/helpers/merge_conflicts_helper.go b/pkg/gui/controllers/helpers/merge_conflicts_helper.go index c84cf4540..3610e28c8 100644 --- a/pkg/gui/controllers/helpers/merge_conflicts_helper.go +++ b/pkg/gui/controllers/helpers/merge_conflicts_helper.go @@ -1,26 +1,19 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" ) type MergeConflictsHelper struct { - c *HelperCommon - contexts *context.ContextTree - git *commands.GitCommand + c *HelperCommon } func NewMergeConflictsHelper( c *HelperCommon, - contexts *context.ContextTree, - git *commands.GitCommand, ) *MergeConflictsHelper { return &MergeConflictsHelper{ - c: c, - contexts: contexts, - git: git, + c: c, } } @@ -32,7 +25,7 @@ func (self *MergeConflictsHelper) SetMergeState(path string) (bool, error) { } func (self *MergeConflictsHelper) setMergeStateWithoutLock(path string) (bool, error) { - content, err := self.git.File.Cat(path) + content, err := self.c.Git().File.Cat(path) if err != nil { return false, err } @@ -63,7 +56,7 @@ func (self *MergeConflictsHelper) EscapeMerge() error { // doing this in separate UI thread so that we're not still holding the lock by the time refresh the file self.c.OnUIThread(func() error { - return self.c.PushContext(self.contexts.Files) + return self.c.PushContext(self.c.Contexts().Files) }) return nil } @@ -92,11 +85,11 @@ func (self *MergeConflictsHelper) SwitchToMerge(path string) error { } } - return self.c.PushContext(self.contexts.MergeConflicts) + return self.c.PushContext(self.c.Contexts().MergeConflicts) } func (self *MergeConflictsHelper) context() *context.MergeConflictsContext { - return self.contexts.MergeConflicts + return self.c.Contexts().MergeConflicts } func (self *MergeConflictsHelper) Render(isFocused bool) error { @@ -119,14 +112,14 @@ func (self *MergeConflictsHelper) Render(isFocused bool) error { } func (self *MergeConflictsHelper) RefreshMergeState() error { - self.contexts.MergeConflicts.GetMutex().Lock() - defer self.contexts.MergeConflicts.GetMutex().Unlock() + self.c.Contexts().MergeConflicts.GetMutex().Lock() + defer self.c.Contexts().MergeConflicts.GetMutex().Unlock() if self.c.CurrentContext().GetKey() != context.MERGE_CONFLICTS_CONTEXT_KEY { return nil } - hasConflicts, err := self.SetConflictsAndRender(self.contexts.MergeConflicts.GetState().GetPath(), true) + hasConflicts, err := self.SetConflictsAndRender(self.c.Contexts().MergeConflicts.GetState().GetPath(), true) if err != nil { return self.c.Error(err) } diff --git a/pkg/gui/controllers/helpers/patch_building_helper.go b/pkg/gui/controllers/helpers/patch_building_helper.go index 08bb8122d..38f850886 100644 --- a/pkg/gui/controllers/helpers/patch_building_helper.go +++ b/pkg/gui/controllers/helpers/patch_building_helper.go @@ -1,9 +1,7 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -13,25 +11,19 @@ type IPatchBuildingHelper interface { } type PatchBuildingHelper struct { - c *HelperCommon - git *commands.GitCommand - contexts *context.ContextTree + c *HelperCommon } func NewPatchBuildingHelper( c *HelperCommon, - git *commands.GitCommand, - contexts *context.ContextTree, ) *PatchBuildingHelper { return &PatchBuildingHelper{ - c: c, - git: git, - contexts: contexts, + c: c, } } func (self *PatchBuildingHelper) ValidateNormalWorkingTreeState() (bool, error) { - if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE { + if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE { return false, self.c.ErrorMsg(self.c.Tr.CantPatchWhileRebasingError) } return true, nil @@ -44,7 +36,7 @@ func (self *PatchBuildingHelper) Escape() error { // kills the custom patch and returns us back to the commit files panel if needed func (self *PatchBuildingHelper) Reset() error { - self.git.Patch.PatchBuilder.Reset() + self.c.Git().Patch.PatchBuilder.Reset() if self.c.CurrentStaticContext().GetKind() != types.SIDE_CONTEXT { if err := self.Escape(); err != nil { @@ -68,30 +60,30 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt selectedLineIdx = opts.ClickedViewLineIdx } - if !self.git.Patch.PatchBuilder.Active() { + if !self.c.Git().Patch.PatchBuilder.Active() { return self.Escape() } // get diff from commit file that's currently selected - path := self.contexts.CommitFiles.GetSelectedPath() + path := self.c.Contexts().CommitFiles.GetSelectedPath() if path == "" { return nil } - ref := self.contexts.CommitFiles.CommitFileTreeViewModel.GetRef() + ref := self.c.Contexts().CommitFiles.CommitFileTreeViewModel.GetRef() to := ref.RefName() from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) - diff, err := self.git.WorkingTree.ShowFileDiff(from, to, reverse, path, true, self.c.State().GetIgnoreWhitespaceInDiffView()) + diff, err := self.c.Git().WorkingTree.ShowFileDiff(from, to, reverse, path, true, self.c.State().GetIgnoreWhitespaceInDiffView()) if err != nil { return err } - secondaryDiff := self.git.Patch.PatchBuilder.RenderPatchForFile(path, false, false) + secondaryDiff := self.c.Git().Patch.PatchBuilder.RenderPatchForFile(path, false, false) if err != nil { return err } - context := self.contexts.CustomPatchBuilder + context := self.c.Contexts().CustomPatchBuilder oldState := context.GetState() @@ -103,7 +95,7 @@ func (self *PatchBuildingHelper) RefreshPatchBuildingPanel(opts types.OnFocusOpt mainContent := context.GetContentToRender(true) - self.contexts.CustomPatchBuilder.FocusSelection() + self.c.Contexts().CustomPatchBuilder.FocusSelection() return self.c.RenderToMainViews(types.RefreshMainOpts{ Pair: self.c.MainViewPairs().PatchBuilding, diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 132c65545..2c3bc4c91 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -7,7 +7,6 @@ import ( "github.com/jesseduffield/generics/set" "github.com/jesseduffield/generics/slices" - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" @@ -22,8 +21,6 @@ import ( type RefreshHelper struct { c *HelperCommon - contexts *context.ContextTree - git *commands.GitCommand refsHelper *RefsHelper mergeAndRebaseHelper *MergeAndRebaseHelper patchBuildingHelper *PatchBuildingHelper @@ -34,8 +31,6 @@ type RefreshHelper struct { func NewRefreshHelper( c *HelperCommon, - contexts *context.ContextTree, - git *commands.GitCommand, refsHelper *RefsHelper, mergeAndRebaseHelper *MergeAndRebaseHelper, patchBuildingHelper *PatchBuildingHelper, @@ -45,8 +40,6 @@ func NewRefreshHelper( ) *RefreshHelper { return &RefreshHelper{ c: c, - contexts: contexts, - git: git, refsHelper: refsHelper, mergeAndRebaseHelper: mergeAndRebaseHelper, patchBuildingHelper: patchBuildingHelper, @@ -239,7 +232,7 @@ func (self *RefreshHelper) refreshCommits() { go utils.Safe(func() { _ = self.refreshCommitsWithLimit() - ctx, ok := self.contexts.CommitFiles.GetParentContext() + ctx, ok := self.c.Contexts().CommitFiles.GetParentContext() if ok && ctx.GetKey() == context.LOCAL_COMMITS_CONTEXT_KEY { // This makes sense when we've e.g. just amended a commit, meaning we get a new commit SHA at the same position. // However if we've just added a brand new commit, it pushes the list down by one and so we would end up @@ -247,10 +240,10 @@ func (self *RefreshHelper) refreshCommits() { // Ideally we would know when to refresh the commit files context and when not to, // or perhaps we could just pop that context off the stack whenever cycling windows. // For now the awkwardness remains. - commit := self.contexts.LocalCommits.GetSelected() + commit := self.c.Contexts().LocalCommits.GetSelected() if commit != nil { - self.contexts.CommitFiles.SetRef(commit) - self.contexts.CommitFiles.SetTitleRef(commit.RefName()) + self.c.Contexts().CommitFiles.SetRef(commit) + self.c.Contexts().CommitFiles.SetTitleRef(commit.RefName()) _ = self.refreshCommitFilesContext() } } @@ -264,34 +257,34 @@ func (self *RefreshHelper) refreshCommitsWithLimit() error { self.c.Mutexes().LocalCommitsMutex.Lock() defer self.c.Mutexes().LocalCommitsMutex.Unlock() - commits, err := self.git.Loaders.CommitLoader.GetCommits( + commits, err := self.c.Git().Loaders.CommitLoader.GetCommits( git_commands.GetCommitsOptions{ - Limit: self.contexts.LocalCommits.GetLimitCommits(), + Limit: self.c.Contexts().LocalCommits.GetLimitCommits(), FilterPath: self.c.Modes().Filtering.GetPath(), IncludeRebaseCommits: true, RefName: self.refForLog(), - All: self.contexts.LocalCommits.GetShowWholeGitGraph(), + All: self.c.Contexts().LocalCommits.GetShowWholeGitGraph(), }, ) if err != nil { return err } self.c.Model().Commits = commits - self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.git.Status.WorkingTreeState() + self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.c.Git().Status.WorkingTreeState() - return self.c.PostRefreshUpdate(self.contexts.LocalCommits) + return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits) } func (self *RefreshHelper) refreshSubCommitsWithLimit() error { self.c.Mutexes().SubCommitsMutex.Lock() defer self.c.Mutexes().SubCommitsMutex.Unlock() - commits, err := self.git.Loaders.CommitLoader.GetCommits( + commits, err := self.c.Git().Loaders.CommitLoader.GetCommits( git_commands.GetCommitsOptions{ - Limit: self.contexts.SubCommits.GetLimitCommits(), + Limit: self.c.Contexts().SubCommits.GetLimitCommits(), FilterPath: self.c.Modes().Filtering.GetPath(), IncludeRebaseCommits: false, - RefName: self.contexts.SubCommits.GetRef().FullRefName(), + RefName: self.c.Contexts().SubCommits.GetRef().FullRefName(), }, ) if err != nil { @@ -299,51 +292,51 @@ func (self *RefreshHelper) refreshSubCommitsWithLimit() error { } self.c.Model().SubCommits = commits - return self.c.PostRefreshUpdate(self.contexts.SubCommits) + return self.c.PostRefreshUpdate(self.c.Contexts().SubCommits) } func (self *RefreshHelper) refreshCommitFilesContext() error { - ref := self.contexts.CommitFiles.GetRef() + ref := self.c.Contexts().CommitFiles.GetRef() to := ref.RefName() from, reverse := self.c.Modes().Diffing.GetFromAndReverseArgsForDiff(ref.ParentRefName()) - files, err := self.git.Loaders.CommitFileLoader.GetFilesInDiff(from, to, reverse) + files, err := self.c.Git().Loaders.CommitFileLoader.GetFilesInDiff(from, to, reverse) if err != nil { return self.c.Error(err) } self.c.Model().CommitFiles = files - self.contexts.CommitFiles.CommitFileTreeViewModel.SetTree() + self.c.Contexts().CommitFiles.CommitFileTreeViewModel.SetTree() - return self.c.PostRefreshUpdate(self.contexts.CommitFiles) + return self.c.PostRefreshUpdate(self.c.Contexts().CommitFiles) } func (self *RefreshHelper) refreshRebaseCommits() error { self.c.Mutexes().LocalCommitsMutex.Lock() defer self.c.Mutexes().LocalCommitsMutex.Unlock() - updatedCommits, err := self.git.Loaders.CommitLoader.MergeRebasingCommits(self.c.Model().Commits) + updatedCommits, err := self.c.Git().Loaders.CommitLoader.MergeRebasingCommits(self.c.Model().Commits) if err != nil { return err } self.c.Model().Commits = updatedCommits - self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.git.Status.WorkingTreeState() + self.c.Model().WorkingTreeStateAtLastCommitRefresh = self.c.Git().Status.WorkingTreeState() - return self.c.PostRefreshUpdate(self.contexts.LocalCommits) + return self.c.PostRefreshUpdate(self.c.Contexts().LocalCommits) } func (self *RefreshHelper) refreshTags() error { - tags, err := self.git.Loaders.TagLoader.GetTags() + tags, err := self.c.Git().Loaders.TagLoader.GetTags() if err != nil { return self.c.Error(err) } self.c.Model().Tags = tags - return self.c.PostRefreshUpdate(self.contexts.Tags) + return self.c.PostRefreshUpdate(self.c.Contexts().Tags) } func (self *RefreshHelper) refreshStateSubmoduleConfigs() error { - configs, err := self.git.Submodule.GetConfigs() + configs, err := self.c.Git().Submodule.GetConfigs() if err != nil { return err } @@ -363,20 +356,20 @@ func (self *RefreshHelper) refreshBranches() { // which allows us to order them correctly. So if we're filtering we'll just // manually load all the reflog commits here var err error - reflogCommits, _, err = self.git.Loaders.ReflogCommitLoader.GetReflogCommits(nil, "") + reflogCommits, _, err = self.c.Git().Loaders.ReflogCommitLoader.GetReflogCommits(nil, "") if err != nil { self.c.Log.Error(err) } } - branches, err := self.git.Loaders.BranchLoader.Load(reflogCommits) + branches, err := self.c.Git().Loaders.BranchLoader.Load(reflogCommits) if err != nil { _ = self.c.Error(err) } self.c.Model().Branches = branches - if err := self.c.PostRefreshUpdate(self.contexts.Branches); err != nil { + if err := self.c.PostRefreshUpdate(self.c.Contexts().Branches); err != nil { self.c.Log.Error(err) } @@ -400,11 +393,11 @@ func (self *RefreshHelper) refreshFilesAndSubmodules() error { } self.c.OnUIThread(func() error { - if err := self.c.PostRefreshUpdate(self.contexts.Submodules); err != nil { + if err := self.c.PostRefreshUpdate(self.c.Contexts().Submodules); err != nil { self.c.Log.Error(err) } - if err := self.c.PostRefreshUpdate(self.contexts.Files); err != nil { + if err := self.c.PostRefreshUpdate(self.c.Contexts().Files); err != nil { self.c.Log.Error(err) } @@ -415,7 +408,7 @@ func (self *RefreshHelper) refreshFilesAndSubmodules() error { } func (self *RefreshHelper) refreshStateFiles() error { - fileTreeViewModel := self.contexts.Files.FileTreeViewModel + fileTreeViewModel := self.c.Contexts().Files.FileTreeViewModel // If git thinks any of our files have inline merge conflicts, but they actually don't, // we stage them. @@ -442,12 +435,12 @@ func (self *RefreshHelper) refreshStateFiles() error { if len(pathsToStage) > 0 { self.c.LogAction(self.c.Tr.Actions.StageResolvedFiles) - if err := self.git.WorkingTree.StageFiles(pathsToStage); err != nil { + if err := self.c.Git().WorkingTree.StageFiles(pathsToStage); err != nil { return self.c.Error(err) } } - files := self.git.Loaders.FileLoader. + files := self.c.Git().Loaders.FileLoader. GetStatusFiles(git_commands.GetStatusFileOptions{}) conflictFileCount := 0 @@ -457,7 +450,7 @@ func (self *RefreshHelper) refreshStateFiles() error { } } - if self.git.Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 { + if self.c.Git().Status.WorkingTreeState() != enums.REBASE_MODE_NONE && conflictFileCount == 0 && prevConflictFileCount > 0 { self.c.OnUIThread(func() error { return self.mergeAndRebaseHelper.PromptToContinueRebase() }) } @@ -504,7 +497,7 @@ func (self *RefreshHelper) refreshReflogCommits() error { } refresh := func(stateCommits *[]*models.Commit, filterPath string) error { - commits, onlyObtainedNewReflogCommits, err := self.git.Loaders.ReflogCommitLoader. + commits, onlyObtainedNewReflogCommits, err := self.c.Git().Loaders.ReflogCommitLoader. GetReflogCommits(lastReflogCommit, filterPath) if err != nil { return self.c.Error(err) @@ -530,13 +523,13 @@ func (self *RefreshHelper) refreshReflogCommits() error { model.FilteredReflogCommits = model.ReflogCommits } - return self.c.PostRefreshUpdate(self.contexts.ReflogCommits) + return self.c.PostRefreshUpdate(self.c.Contexts().ReflogCommits) } func (self *RefreshHelper) refreshRemotes() error { - prevSelectedRemote := self.contexts.Remotes.GetSelected() + prevSelectedRemote := self.c.Contexts().Remotes.GetSelected() - remotes, err := self.git.Loaders.RemoteLoader.GetRemotes() + remotes, err := self.c.Git().Loaders.RemoteLoader.GetRemotes() if err != nil { return self.c.Error(err) } @@ -554,11 +547,11 @@ func (self *RefreshHelper) refreshRemotes() error { } } - if err := self.c.PostRefreshUpdate(self.contexts.Remotes); err != nil { + if err := self.c.PostRefreshUpdate(self.c.Contexts().Remotes); err != nil { return err } - if err := self.c.PostRefreshUpdate(self.contexts.RemoteBranches); err != nil { + if err := self.c.PostRefreshUpdate(self.c.Contexts().RemoteBranches); err != nil { return err } @@ -566,10 +559,10 @@ func (self *RefreshHelper) refreshRemotes() error { } func (self *RefreshHelper) refreshStashEntries() error { - self.c.Model().StashEntries = self.git.Loaders.StashLoader. + self.c.Model().StashEntries = self.c.Git().Loaders.StashLoader. GetStashEntries(self.c.Modes().Filtering.GetPath()) - return self.c.PostRefreshUpdate(self.contexts.Stash) + return self.c.PostRefreshUpdate(self.c.Contexts().Stash) } // never call this on its own, it should only be called from within refreshCommits() @@ -588,7 +581,7 @@ func (self *RefreshHelper) refreshStatus() { status += presentation.ColoredBranchStatus(currentBranch, self.c.Tr) + " " } - workingTreeState := self.git.Status.WorkingTreeState() + workingTreeState := self.c.Git().Status.WorkingTreeState() if workingTreeState != enums.REBASE_MODE_NONE { status += style.FgYellow.Sprintf("(%s) ", presentation.FormatWorkingTreeState(workingTreeState)) } @@ -601,7 +594,7 @@ func (self *RefreshHelper) refreshStatus() { } func (self *RefreshHelper) refForLog() string { - bisectInfo := self.git.Bisect.GetInfo() + bisectInfo := self.c.Git().Bisect.GetInfo() self.c.Model().BisectInfo = bisectInfo if !bisectInfo.Started() { @@ -609,7 +602,7 @@ func (self *RefreshHelper) refForLog() string { } // need to see if our bisect's current commit is reachable from our 'new' ref. - if bisectInfo.Bisecting() && !self.git.Bisect.ReachableFromStart(bisectInfo) { + if bisectInfo.Bisecting() && !self.c.Git().Bisect.ReachableFromStart(bisectInfo) { return bisectInfo.GetNewSha() } diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index ad295e59c..f40a2ad10 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -5,10 +5,8 @@ import ( "strings" "github.com/jesseduffield/generics/slices" - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -23,23 +21,14 @@ type IRefsHelper interface { } type RefsHelper struct { - c *HelperCommon - git *commands.GitCommand - contexts *context.ContextTree - model *types.Model + c *HelperCommon } func NewRefsHelper( c *HelperCommon, - git *commands.GitCommand, - contexts *context.ContextTree, - model *types.Model, ) *RefsHelper { return &RefsHelper{ - c: c, - git: git, - contexts: contexts, - model: model, + c: c, } } @@ -54,15 +43,15 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions cmdOptions := git_commands.CheckoutOptions{Force: false, EnvVars: options.EnvVars} onSuccess := func() { - self.contexts.Branches.SetSelectedLineIdx(0) - self.contexts.ReflogCommits.SetSelectedLineIdx(0) - self.contexts.LocalCommits.SetSelectedLineIdx(0) + self.c.Contexts().Branches.SetSelectedLineIdx(0) + self.c.Contexts().ReflogCommits.SetSelectedLineIdx(0) + self.c.Contexts().LocalCommits.SetSelectedLineIdx(0) // loading a heap of commits is slow so we limit them whenever doing a reset - self.contexts.LocalCommits.SetLimitCommits(true) + self.c.Contexts().LocalCommits.SetLimitCommits(true) } return self.c.WithWaitingStatus(waitingStatus, func() error { - if err := self.git.Branch.Checkout(ref, cmdOptions); err != nil { + if err := self.c.Git().Branch.Checkout(ref, cmdOptions); err != nil { // note, this will only work for english-language git commands. If we force git to use english, and the error isn't this one, then the user will receive an english command they may not understand. I'm not sure what the best solution to this is. Running the command once in english and a second time in the native language is one option if options.OnRefNotFound != nil && strings.Contains(err.Error(), "did not match any file(s) known to git") { @@ -75,15 +64,15 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions Title: self.c.Tr.AutoStashTitle, Prompt: self.c.Tr.AutoStashPrompt, HandleConfirm: func() error { - if err := self.git.Stash.Save(self.c.Tr.StashPrefix + ref); err != nil { + if err := self.c.Git().Stash.Save(self.c.Tr.StashPrefix + ref); err != nil { return self.c.Error(err) } - if err := self.git.Branch.Checkout(ref, cmdOptions); err != nil { + if err := self.c.Git().Branch.Checkout(ref, cmdOptions); err != nil { return self.c.Error(err) } onSuccess() - if err := self.git.Stash.Pop(0); err != nil { + if err := self.c.Git().Stash.Pop(0); err != nil { if err := self.c.Refresh(types.RefreshOptions{Mode: types.BLOCK_UI}); err != nil { return err } @@ -105,22 +94,22 @@ func (self *RefsHelper) CheckoutRef(ref string, options types.CheckoutRefOptions } func (self *RefsHelper) GetCheckedOutRef() *models.Branch { - if len(self.model.Branches) == 0 { + if len(self.c.Model().Branches) == 0 { return nil } - return self.model.Branches[0] + return self.c.Model().Branches[0] } func (self *RefsHelper) ResetToRef(ref string, strength string, envVars []string) error { - if err := self.git.Commit.ResetToCommit(ref, strength, envVars); err != nil { + if err := self.c.Git().Commit.ResetToCommit(ref, strength, envVars); err != nil { return self.c.Error(err) } - self.contexts.LocalCommits.SetSelectedLineIdx(0) - self.contexts.ReflogCommits.SetSelectedLineIdx(0) + self.c.Contexts().LocalCommits.SetSelectedLineIdx(0) + self.c.Contexts().ReflogCommits.SetSelectedLineIdx(0) // loading a heap of commits is slow so we limit them whenever doing a reset - self.contexts.LocalCommits.SetLimitCommits(true) + self.c.Contexts().LocalCommits.SetLimitCommits(true) if err := self.c.Refresh(types.RefreshOptions{Scope: []types.RefreshableView{types.FILES, types.BRANCHES, types.REFLOG, types.COMMITS}}); err != nil { return err @@ -173,18 +162,18 @@ func (self *RefsHelper) NewBranch(from string, fromFormattedName string, suggest InitialContent: suggestedBranchName, HandleConfirm: func(response string) error { self.c.LogAction(self.c.Tr.Actions.CreateBranch) - if err := self.git.Branch.New(sanitizedBranchName(response), from); err != nil { + if err := self.c.Git().Branch.New(sanitizedBranchName(response), from); err != nil { return err } - if self.c.CurrentContext() != self.contexts.Branches { - if err := self.c.PushContext(self.contexts.Branches); err != nil { + if self.c.CurrentContext() != self.c.Contexts().Branches { + if err := self.c.PushContext(self.c.Contexts().Branches); err != nil { return err } } - self.contexts.LocalCommits.SetSelectedLineIdx(0) - self.contexts.Branches.SetSelectedLineIdx(0) + self.c.Contexts().LocalCommits.SetSelectedLineIdx(0) + self.c.Contexts().Branches.SetSelectedLineIdx(0) return self.c.Refresh(types.RefreshOptions{Mode: types.ASYNC}) }, diff --git a/pkg/gui/controllers/helpers/staging_helper.go b/pkg/gui/controllers/helpers/staging_helper.go index dee6a0fa1..da67de9b8 100644 --- a/pkg/gui/controllers/helpers/staging_helper.go +++ b/pkg/gui/controllers/helpers/staging_helper.go @@ -1,28 +1,20 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/patch_exploring" "github.com/jesseduffield/lazygit/pkg/gui/types" ) type StagingHelper struct { - c *HelperCommon - git *commands.GitCommand - contexts *context.ContextTree + c *HelperCommon } func NewStagingHelper( c *HelperCommon, - git *commands.GitCommand, - contexts *context.ContextTree, ) *StagingHelper { return &StagingHelper{ - c: c, - git: git, - contexts: contexts, + c: c, } } @@ -40,11 +32,11 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro } } - mainContext := self.contexts.Staging - secondaryContext := self.contexts.StagingSecondary + mainContext := self.c.Contexts().Staging + secondaryContext := self.c.Contexts().StagingSecondary var file *models.File - node := self.contexts.Files.GetSelected() + node := self.c.Contexts().Files.GetSelected() if node != nil { file = node.File } @@ -53,8 +45,8 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro return self.handleStagingEscape() } - mainDiff := self.git.WorkingTree.WorktreeFileDiff(file, true, false, false) - secondaryDiff := self.git.WorkingTree.WorktreeFileDiff(file, true, true, false) + mainDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, false, false) + secondaryDiff := self.c.Git().WorkingTree.WorktreeFileDiff(file, true, true, false) // grabbing locks here and releasing before we finish the function // because pushing say the secondary context could mean entering this function @@ -92,9 +84,9 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro } if secondaryFocused { - self.contexts.StagingSecondary.FocusSelection() + self.c.Contexts().StagingSecondary.FocusSelection() } else { - self.contexts.Staging.FocusSelection() + self.c.Contexts().Staging.FocusSelection() } return self.c.RenderToMainViews(types.RefreshMainOpts{ @@ -111,9 +103,9 @@ func (self *StagingHelper) RefreshStagingPanel(focusOpts types.OnFocusOpts) erro } func (self *StagingHelper) handleStagingEscape() error { - return self.c.PushContext(self.contexts.Files) + return self.c.PushContext(self.c.Contexts().Files) } func (self *StagingHelper) secondaryStagingFocused() bool { - return self.c.CurrentStaticContext().GetKey() == self.contexts.StagingSecondary.GetKey() + return self.c.CurrentStaticContext().GetKey() == self.c.Contexts().StagingSecondary.GetKey() } diff --git a/pkg/gui/controllers/helpers/suggestions_helper.go b/pkg/gui/controllers/helpers/suggestions_helper.go index 206fd371a..2234e3c2b 100644 --- a/pkg/gui/controllers/helpers/suggestions_helper.go +++ b/pkg/gui/controllers/helpers/suggestions_helper.go @@ -6,7 +6,6 @@ import ( "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/models" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" @@ -35,27 +34,20 @@ type ISuggestionsHelper interface { type SuggestionsHelper struct { c *HelperCommon - - model *types.Model - contexts *context.ContextTree } var _ ISuggestionsHelper = &SuggestionsHelper{} func NewSuggestionsHelper( c *HelperCommon, - model *types.Model, - contexts *context.ContextTree, ) *SuggestionsHelper { return &SuggestionsHelper{ - c: c, - model: model, - contexts: contexts, + c: c, } } func (self *SuggestionsHelper) getRemoteNames() []string { - return slices.Map(self.model.Remotes, func(remote *models.Remote) string { + return slices.Map(self.c.Model().Remotes, func(remote *models.Remote) string { return remote.Name }) } @@ -76,7 +68,7 @@ func (self *SuggestionsHelper) GetRemoteSuggestionsFunc() func(string) []*types. } func (self *SuggestionsHelper) getBranchNames() []string { - return slices.Map(self.model.Branches, func(branch *models.Branch) string { + return slices.Map(self.c.Model().Branches, func(branch *models.Branch) string { return branch.Name }) } @@ -102,8 +94,8 @@ func (self *SuggestionsHelper) GetBranchNameSuggestionsFunc() func(string) []*ty } // here we asynchronously fetch the latest set of paths in the repo and store in -// self.model.FilesTrie. On the main thread we'll be doing a fuzzy search via -// self.model.FilesTrie. So if we've looked for a file previously, we'll start with +// self.c.Model().FilesTrie. On the main thread we'll be doing a fuzzy search via +// self.c.Model().FilesTrie. So if we've looked for a file previously, we'll start with // the old trie and eventually it'll be swapped out for the new one. // Notably, unlike other suggestion functions we're not showing all the options // if nothing has been typed because there'll be too much to display efficiently @@ -126,16 +118,16 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type }) // cache the trie for future use - self.model.FilesTrie = trie + self.c.Model().FilesTrie = trie - self.contexts.Suggestions.RefreshSuggestions() + self.c.Contexts().Suggestions.RefreshSuggestions() return err }) return func(input string) []*types.Suggestion { matchingNames := []string{} - _ = self.model.FilesTrie.VisitFuzzy(patricia.Prefix(input), true, func(prefix patricia.Prefix, item patricia.Item, skipped int) error { + _ = self.c.Model().FilesTrie.VisitFuzzy(patricia.Prefix(input), true, func(prefix patricia.Prefix, item patricia.Item, skipped int) error { matchingNames = append(matchingNames, item.(string)) return nil }) @@ -148,7 +140,7 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type } func (self *SuggestionsHelper) getRemoteBranchNames(separator string) []string { - return slices.FlatMap(self.model.Remotes, func(remote *models.Remote) []string { + return slices.FlatMap(self.c.Model().Remotes, func(remote *models.Remote) []string { return slices.Map(remote.Branches, func(branch *models.RemoteBranch) string { return fmt.Sprintf("%s%s%s", remote.Name, separator, branch.Name) }) @@ -160,7 +152,7 @@ func (self *SuggestionsHelper) GetRemoteBranchesSuggestionsFunc(separator string } func (self *SuggestionsHelper) getTagNames() []string { - return slices.Map(self.model.Tags, func(tag *models.Tag) string { + return slices.Map(self.c.Model().Tags, func(tag *models.Tag) string { return tag.Name }) } @@ -177,7 +169,7 @@ func (self *SuggestionsHelper) GetRefsSuggestionsFunc() func(string) []*types.Su } func (self *SuggestionsHelper) GetAuthorsSuggestionsFunc() func(string) []*types.Suggestion { - authors := lo.Uniq(slices.Map(self.model.Commits, func(commit *models.Commit) string { + authors := lo.Uniq(slices.Map(self.c.Model().Commits, func(commit *models.Commit) string { return fmt.Sprintf("%s <%s>", commit.AuthorName, commit.AuthorEmail) })) diff --git a/pkg/gui/controllers/helpers/tags_helper.go b/pkg/gui/controllers/helpers/tags_helper.go index 7f17be222..d3cbf2331 100644 --- a/pkg/gui/controllers/helpers/tags_helper.go +++ b/pkg/gui/controllers/helpers/tags_helper.go @@ -1,7 +1,6 @@ package helpers import ( - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/gui/types" ) @@ -10,14 +9,12 @@ import ( // and the commits context. type TagsHelper struct { - c *HelperCommon - git *commands.GitCommand + c *HelperCommon } -func NewTagsHelper(c *HelperCommon, git *commands.GitCommand) *TagsHelper { +func NewTagsHelper(c *HelperCommon) *TagsHelper { return &TagsHelper{ - c: c, - git: git, + c: c, } } @@ -56,7 +53,7 @@ func (self *TagsHelper) handleCreateAnnotatedTag(ref string, onCreate func()) er Title: self.c.Tr.TagMessageTitle, HandleConfirm: func(msg string) error { self.c.LogAction(self.c.Tr.Actions.CreateAnnotatedTag) - if err := self.git.Tag.CreateAnnotated(tagName, ref, msg); err != nil { + if err := self.c.Git().Tag.CreateAnnotated(tagName, ref, msg); err != nil { return self.c.Error(err) } return self.afterTagCreate(onCreate) @@ -71,7 +68,7 @@ func (self *TagsHelper) handleCreateLightweightTag(ref string, onCreate func()) Title: self.c.Tr.TagNameTitle, HandleConfirm: func(tagName string) error { self.c.LogAction(self.c.Tr.Actions.CreateLightweightTag) - if err := self.git.Tag.CreateLightweight(tagName, ref); err != nil { + if err := self.c.Git().Tag.CreateLightweight(tagName, ref); err != nil { return self.c.Error(err) } return self.afterTagCreate(onCreate) diff --git a/pkg/gui/controllers/helpers/upstream_helper.go b/pkg/gui/controllers/helpers/upstream_helper.go index b4825ffaa..ea3187ed8 100644 --- a/pkg/gui/controllers/helpers/upstream_helper.go +++ b/pkg/gui/controllers/helpers/upstream_helper.go @@ -9,8 +9,7 @@ import ( ) type UpstreamHelper struct { - c *HelperCommon - model *types.Model + c *HelperCommon getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion } @@ -26,12 +25,10 @@ var _ IUpstreamHelper = &UpstreamHelper{} func NewUpstreamHelper( c *HelperCommon, - model *types.Model, getRemoteBranchesSuggestionsFunc func(string) func(string) []*types.Suggestion, ) *UpstreamHelper { return &UpstreamHelper{ c: c, - model: model, getRemoteBranchesSuggestionsFunc: getRemoteBranchesSuggestionsFunc, } } @@ -70,7 +67,7 @@ func (self *UpstreamHelper) PromptForUpstreamWithoutInitialContent(_ *models.Bra } func (self *UpstreamHelper) GetSuggestedRemote() string { - return getSuggestedRemote(self.model.Remotes) + return getSuggestedRemote(self.c.Model().Remotes) } func getSuggestedRemote(remotes []*models.Remote) string { diff --git a/pkg/gui/controllers/helpers/view_helper.go b/pkg/gui/controllers/helpers/view_helper.go index e1d837da5..c8d9ad94e 100644 --- a/pkg/gui/controllers/helpers/view_helper.go +++ b/pkg/gui/controllers/helpers/view_helper.go @@ -6,14 +6,12 @@ import ( ) type ViewHelper struct { - c *HelperCommon - contexts *context.ContextTree + c *HelperCommon } func NewViewHelper(c *HelperCommon, contexts *context.ContextTree) *ViewHelper { return &ViewHelper{ - c: c, - contexts: contexts, + c: c, } } @@ -23,7 +21,7 @@ func (self *ViewHelper) ContextForView(viewName string) (types.Context, bool) { return nil, false } - for _, context := range self.contexts.Flatten() { + for _, context := range self.c.Contexts().Flatten() { if context.GetViewName() == view.Name() { return context, true } diff --git a/pkg/gui/controllers/helpers/window_helper.go b/pkg/gui/controllers/helpers/window_helper.go index 8754cc41d..7c4edf35b 100644 --- a/pkg/gui/controllers/helpers/window_helper.go +++ b/pkg/gui/controllers/helpers/window_helper.go @@ -4,7 +4,6 @@ import ( "fmt" "github.com/jesseduffield/gocui" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" @@ -13,14 +12,12 @@ import ( type WindowHelper struct { c *HelperCommon viewHelper *ViewHelper - contexts *context.ContextTree } -func NewWindowHelper(c *HelperCommon, viewHelper *ViewHelper, contexts *context.ContextTree) *WindowHelper { +func NewWindowHelper(c *HelperCommon, viewHelper *ViewHelper) *WindowHelper { return &WindowHelper{ c: c, viewHelper: viewHelper, - contexts: contexts, } } @@ -75,7 +72,7 @@ func (self *WindowHelper) resetWindowContext(c types.Context) { continue } if viewName == c.GetViewName() && windowName != c.GetWindowName() { - for _, context := range self.contexts.Flatten() { + for _, context := range self.c.Contexts().Flatten() { if context.GetKey() != c.GetKey() && context.GetWindowName() == windowName { self.windowViewNameMap().Set(windowName, context.GetViewName()) } @@ -119,7 +116,7 @@ func (self *WindowHelper) TopViewInWindow(windowName string) *gocui.View { func (self *WindowHelper) viewNamesInWindow(windowName string) []string { result := []string{} - for _, context := range self.contexts.Flatten() { + for _, context := range self.c.Contexts().Flatten() { if context.GetWindowName() == windowName { result = append(result, context.GetViewName()) } diff --git a/pkg/gui/controllers/helpers/working_tree_helper.go b/pkg/gui/controllers/helpers/working_tree_helper.go index 1e3c211b0..5eb67e124 100644 --- a/pkg/gui/controllers/helpers/working_tree_helper.go +++ b/pkg/gui/controllers/helpers/working_tree_helper.go @@ -4,10 +4,8 @@ import ( "fmt" "regexp" - "github.com/jesseduffield/lazygit/pkg/commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/config" - "github.com/jesseduffield/lazygit/pkg/gui/context" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" ) @@ -21,36 +19,27 @@ type IWorkingTreeHelper interface { type WorkingTreeHelper struct { c *HelperCommon - git *commands.GitCommand - contexts *context.ContextTree refHelper *RefsHelper - model *types.Model setCommitMessage func(message string) getSavedCommitMessage func() string } func NewWorkingTreeHelper( c *HelperCommon, - git *commands.GitCommand, - contexts *context.ContextTree, refHelper *RefsHelper, - model *types.Model, setCommitMessage func(message string), getSavedCommitMessage func() string, ) *WorkingTreeHelper { return &WorkingTreeHelper{ c: c, - git: git, - contexts: contexts, refHelper: refHelper, - model: model, setCommitMessage: setCommitMessage, getSavedCommitMessage: getSavedCommitMessage, } } func (self *WorkingTreeHelper) AnyStagedFiles() bool { - for _, file := range self.model.Files { + for _, file := range self.c.Model().Files { if file.HasStagedChanges { return true } @@ -59,7 +48,7 @@ func (self *WorkingTreeHelper) AnyStagedFiles() bool { } func (self *WorkingTreeHelper) AnyTrackedFiles() bool { - for _, file := range self.model.Files { + for _, file := range self.c.Model().Files { if file.Tracked { return true } @@ -72,7 +61,7 @@ func (self *WorkingTreeHelper) IsWorkingTreeDirty() bool { } func (self *WorkingTreeHelper) FileForSubmodule(submodule *models.SubmoduleConfig) *models.File { - for _, file := range self.model.Files { + for _, file := range self.c.Model().Files { if file.IsSubmodule([]*models.SubmoduleConfig{submodule}) { return file } @@ -88,7 +77,7 @@ func (self *WorkingTreeHelper) OpenMergeTool() error { HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.OpenMergeTool) return self.c.RunSubprocessAndRefresh( - self.git.WorkingTree.OpenMergeToolCmdObj(), + self.c.Git().WorkingTree.OpenMergeToolCmdObj(), ) }, }) @@ -99,7 +88,7 @@ func (self *WorkingTreeHelper) HandleCommitPress() error { return self.c.Error(err) } - if len(self.model.Files) == 0 { + if len(self.c.Model().Files) == 0 { return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle) } @@ -124,7 +113,7 @@ func (self *WorkingTreeHelper) HandleCommitPress() error { } } - if err := self.c.PushContext(self.contexts.CommitMessage); err != nil { + if err := self.c.PushContext(self.c.Contexts().CommitMessage); err != nil { return err } @@ -134,7 +123,7 @@ func (self *WorkingTreeHelper) HandleCommitPress() error { // HandleCommitEditorPress - handle when the user wants to commit changes via // their editor rather than via the popup panel func (self *WorkingTreeHelper) HandleCommitEditorPress() error { - if len(self.model.Files) == 0 { + if len(self.c.Model().Files) == 0 { return self.c.ErrorMsg(self.c.Tr.NoFilesStagedTitle) } @@ -144,7 +133,7 @@ func (self *WorkingTreeHelper) HandleCommitEditorPress() error { self.c.LogAction(self.c.Tr.Actions.Commit) return self.c.RunSubprocessAndRefresh( - self.git.Commit.CommitEditorCmdObj(), + self.c.Git().Commit.CommitEditorCmdObj(), ) } @@ -165,7 +154,7 @@ func (self *WorkingTreeHelper) PromptToStageAllAndRetry(retry func() error) erro Prompt: self.c.Tr.NoFilesStagedPrompt, HandleConfirm: func() error { self.c.LogAction(self.c.Tr.Actions.StageAllFiles) - if err := self.git.WorkingTree.StageAll(); err != nil { + if err := self.c.Git().WorkingTree.StageAll(); err != nil { return self.c.Error(err) } if err := self.syncRefresh(); err != nil { @@ -186,7 +175,7 @@ func (self *WorkingTreeHelper) prepareFilesForCommit() error { noStagedFiles := !self.AnyStagedFiles() if noStagedFiles && self.c.UserConfig.Gui.SkipNoStagedFilesWarning { self.c.LogAction(self.c.Tr.Actions.StageAllFiles) - err := self.git.WorkingTree.StageAll() + err := self.c.Git().WorkingTree.StageAll() if err != nil { return err }