From 3f44eac95b3835bdd00b84aafca9ae0bc80ad7dd Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Fri, 7 Jan 2022 15:07:35 +1100 Subject: remove repo field --- pkg/commands/config.go | 13 +++++++++++++ pkg/commands/git.go | 4 ---- pkg/gui/files_panel.go | 8 ++++---- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/pkg/commands/config.go b/pkg/commands/config.go index db918ec86..52eb82ac3 100644 --- a/pkg/commands/config.go +++ b/pkg/commands/config.go @@ -5,6 +5,8 @@ import ( "strconv" "strings" + gogit "github.com/jesseduffield/go-git/v5" + "github.com/jesseduffield/go-git/v5/config" "github.com/jesseduffield/lazygit/pkg/commands/git_config" "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/utils" @@ -14,6 +16,7 @@ type ConfigCommands struct { *common.Common gitConfig git_config.IGitConfig + repo *gogit.Repository } func NewConfigCommands( @@ -80,3 +83,13 @@ func (self *ConfigCommands) GetShowUntrackedFiles() string { func (self *ConfigCommands) GetPushToCurrent() bool { return self.gitConfig.Get("push.default") == "current" } + +// returns the repo's branches as specified in the git config +func (self *ConfigCommands) Branches() (map[string]*config.Branch, error) { + conf, err := self.repo.Config() + if err != nil { + return nil, err + } + + return conf.Branches, nil +} diff --git a/pkg/commands/git.go b/pkg/commands/git.go index 2f38757f7..d7915328c 100644 --- a/pkg/commands/git.go +++ b/pkg/commands/git.go @@ -22,8 +22,6 @@ import ( type GitCommand struct { *common.Common - Repo *gogit.Repository - Loaders Loaders Cmd oscommands.ICmdObjBuilder @@ -123,8 +121,6 @@ func NewGitCommandAux( return &GitCommand{ Common: cmn, - Repo: repo, - Cmd: cmd, Submodule: submoduleCommands, diff --git a/pkg/gui/files_panel.go b/pkg/gui/files_panel.go index 855a8f851..fcf8d021c 100644 --- a/pkg/gui/files_panel.go +++ b/pkg/gui/files_panel.go @@ -668,11 +668,11 @@ func (gui *Gui) handlePullFiles() error { // if we have no upstream branch we need to set that first if !currentBranch.IsTrackingRemote() { // see if we have this branch in our config with an upstream - conf, err := gui.GitCommand.Repo.Config() + branches, err := gui.GitCommand.Config.Branches() if err != nil { return gui.surfaceError(err) } - for branchName, branch := range conf.Branches { + for branchName, branch := range branches { if branchName == currentBranch.Name { return gui.pullFiles(PullFilesOptions{RemoteName: branch.Remote, BranchName: branch.Name, action: action}) } @@ -878,12 +878,12 @@ func (gui *Gui) requestToForcePush() error { } func (gui *Gui) upstreamForBranchInConfig(branchName string) (string, string, error) { - conf, err := gui.GitCommand.Repo.Config() + branches, err := gui.GitCommand.Config.Branches() if err != nil { return "", "", err } - for configBranchName, configBranch := range conf.Branches { + for configBranchName, configBranch := range branches { if configBranchName == branchName { return configBranch.Remote, configBranchName, nil } -- cgit v1.2.3