diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2021-12-30 17:36:21 +1100 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2022-01-04 09:07:15 +1100 |
commit | 44b6d26b100a98d999127e6b418fdff25fcebc1c (patch) | |
tree | d5f1fd2638827ad093613b3cdc18e2b54dd1f47d | |
parent | d69ce7a529474565ea61f1e104d3e42cd55ff8e1 (diff) |
move remotes loader into loaders package
-rw-r--r-- | pkg/commands/loaders/reflog_commits.go (renamed from pkg/commands/loaders/loading_reflog_commits.go) | 0 | ||||
-rw-r--r-- | pkg/commands/loaders/remotes.go (renamed from pkg/commands/loading_remotes.go) | 29 | ||||
-rw-r--r-- | pkg/gui/remotes_panel.go | 3 |
3 files changed, 27 insertions, 5 deletions
diff --git a/pkg/commands/loaders/loading_reflog_commits.go b/pkg/commands/loaders/reflog_commits.go index 012c7c297..012c7c297 100644 --- a/pkg/commands/loaders/loading_reflog_commits.go +++ b/pkg/commands/loaders/reflog_commits.go diff --git a/pkg/commands/loading_remotes.go b/pkg/commands/loaders/remotes.go index 0a581fff5..c0734ab32 100644 --- a/pkg/commands/loading_remotes.go +++ b/pkg/commands/loaders/remotes.go @@ -1,4 +1,4 @@ -package commands +package loaders import ( "fmt" @@ -6,16 +6,37 @@ import ( "sort" "strings" + gogit "github.com/jesseduffield/go-git/v5" "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/common" ) -func (c *GitCommand) GetRemotes() ([]*models.Remote, error) { - remoteBranchesStr, err := c.Cmd.New("git branch -r").RunWithOutput() +type RemoteLoader struct { + *common.Common + cmd oscommands.ICmdObjBuilder + getGoGitRemotes func() ([]*gogit.Remote, error) +} + +func NewRemoteLoader( + common *common.Common, + cmd oscommands.ICmdObjBuilder, + getGoGitRemotes func() ([]*gogit.Remote, error), +) *RemoteLoader { + return &RemoteLoader{ + Common: common, + cmd: cmd, + getGoGitRemotes: getGoGitRemotes, + } +} + +func (self *RemoteLoader) GetRemotes() ([]*models.Remote, error) { + remoteBranchesStr, err := self.cmd.New("git branch -r").RunWithOutput() if err != nil { return nil, err } - goGitRemotes, err := c.Repo.Remotes() + goGitRemotes, err := self.getGoGitRemotes() if err != nil { return nil, err } diff --git a/pkg/gui/remotes_panel.go b/pkg/gui/remotes_panel.go index 1731aacba..999ec1a10 100644 --- a/pkg/gui/remotes_panel.go +++ b/pkg/gui/remotes_panel.go @@ -4,6 +4,7 @@ import ( "fmt" "strings" + "github.com/jesseduffield/lazygit/pkg/commands/loaders" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/utils" @@ -40,7 +41,7 @@ func (gui *Gui) remotesRenderToMain() error { func (gui *Gui) refreshRemotes() error { prevSelectedRemote := gui.getSelectedRemote() - remotes, err := gui.GitCommand.GetRemotes() + remotes, err := loaders.NewRemoteLoader(gui.Common, gui.GitCommand.Cmd, gui.GitCommand.Repo.Remotes).GetRemotes() if err != nil { return gui.surfaceError(err) } |