1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-04-19 12:12:42 +02:00

remove repo field

This commit is contained in:
Jesse Duffield 2022-01-07 15:07:35 +11:00
parent 946a35b59d
commit 3f44eac95b
3 changed files with 17 additions and 8 deletions

View File

@ -5,6 +5,8 @@ import (
"strconv" "strconv"
"strings" "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/commands/git_config"
"github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/common"
"github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/lazygit/pkg/utils"
@ -14,6 +16,7 @@ type ConfigCommands struct {
*common.Common *common.Common
gitConfig git_config.IGitConfig gitConfig git_config.IGitConfig
repo *gogit.Repository
} }
func NewConfigCommands( func NewConfigCommands(
@ -80,3 +83,13 @@ func (self *ConfigCommands) GetShowUntrackedFiles() string {
func (self *ConfigCommands) GetPushToCurrent() bool { func (self *ConfigCommands) GetPushToCurrent() bool {
return self.gitConfig.Get("push.default") == "current" 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
}

View File

@ -22,8 +22,6 @@ import (
type GitCommand struct { type GitCommand struct {
*common.Common *common.Common
Repo *gogit.Repository
Loaders Loaders Loaders Loaders
Cmd oscommands.ICmdObjBuilder Cmd oscommands.ICmdObjBuilder
@ -123,8 +121,6 @@ func NewGitCommandAux(
return &GitCommand{ return &GitCommand{
Common: cmn, Common: cmn,
Repo: repo,
Cmd: cmd, Cmd: cmd,
Submodule: submoduleCommands, Submodule: submoduleCommands,

View File

@ -668,11 +668,11 @@ func (gui *Gui) handlePullFiles() error {
// if we have no upstream branch we need to set that first // if we have no upstream branch we need to set that first
if !currentBranch.IsTrackingRemote() { if !currentBranch.IsTrackingRemote() {
// see if we have this branch in our config with an upstream // 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 { if err != nil {
return gui.surfaceError(err) return gui.surfaceError(err)
} }
for branchName, branch := range conf.Branches { for branchName, branch := range branches {
if branchName == currentBranch.Name { if branchName == currentBranch.Name {
return gui.pullFiles(PullFilesOptions{RemoteName: branch.Remote, BranchName: branch.Name, action: action}) 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) { func (gui *Gui) upstreamForBranchInConfig(branchName string) (string, string, error) {
conf, err := gui.GitCommand.Repo.Config() branches, err := gui.GitCommand.Config.Branches()
if err != nil { if err != nil {
return "", "", err return "", "", err
} }
for configBranchName, configBranch := range conf.Branches { for configBranchName, configBranch := range branches {
if configBranchName == branchName { if configBranchName == branchName {
return configBranch.Remote, configBranchName, nil return configBranch.Remote, configBranchName, nil
} }