diff --git a/pkg/commands/git_commands/commit_loader_test.go b/pkg/commands/git_commands/commit_loader_test.go index 9c9138062..f9c4cdff6 100644 --- a/pkg/commands/git_commands/commit_loader_test.go +++ b/pkg/commands/git_commands/commit_loader_test.go @@ -324,7 +324,7 @@ func TestGetCommits(t *testing.T) { common.UserConfig().Git.MainBranches = scenario.mainBranches opts := scenario.opts - opts.MainBranches = NewMainBranches(scenario.mainBranches, cmd) + opts.MainBranches = NewMainBranches(common, cmd) commits, err := builder.GetCommits(opts) assert.Equal(t, scenario.expectedCommits, commits) diff --git a/pkg/commands/git_commands/main_branches.go b/pkg/commands/git_commands/main_branches.go index 341232b04..85ac6f174 100644 --- a/pkg/commands/git_commands/main_branches.go +++ b/pkg/commands/git_commands/main_branches.go @@ -5,17 +5,17 @@ import ( "sync" "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/common" "github.com/jesseduffield/lazygit/pkg/utils" "github.com/samber/lo" "github.com/sasha-s/go-deadlock" ) type MainBranches struct { - // List of main branches configured by the user. Just the bare names. - configuredMainBranches []string - // Which of these actually exist in the repository. Full ref names, and it - // could be either "refs/heads/..." or "refs/remotes/origin/..." depending - // on which one exists for a given bare name. + c *common.Common + // Which of the configured main branches actually exist in the repository. Full + // ref names, and it could be either "refs/heads/..." or "refs/remotes/origin/..." + // depending on which one exists for a given bare name. existingMainBranches []string cmd oscommands.ICmdObjBuilder @@ -23,14 +23,14 @@ type MainBranches struct { } func NewMainBranches( - configuredMainBranches []string, + cmn *common.Common, cmd oscommands.ICmdObjBuilder, ) *MainBranches { return &MainBranches{ - configuredMainBranches: configuredMainBranches, - existingMainBranches: nil, - cmd: cmd, - mutex: &deadlock.Mutex{}, + c: cmn, + existingMainBranches: nil, + cmd: cmd, + mutex: &deadlock.Mutex{}, } } @@ -75,9 +75,10 @@ func (self *MainBranches) determineMainBranches() []string { var existingBranches []string var wg sync.WaitGroup - existingBranches = make([]string, len(self.configuredMainBranches)) + configuredMainBranches := self.c.UserConfig().Git.MainBranches + existingBranches = make([]string, len(configuredMainBranches)) - for i, branchName := range self.configuredMainBranches { + for i, branchName := range configuredMainBranches { wg.Add(1) go utils.Safe(func() { defer wg.Done() diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 05e68d3f7..7f305c0bd 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -456,7 +456,7 @@ func (gui *Gui) resetState(startArgs appTypes.StartArgs) types.Context { BisectInfo: git_commands.NewNullBisectInfo(), FilesTrie: patricia.NewTrie(), Authors: map[string]*models.Author{}, - MainBranches: git_commands.NewMainBranches(gui.UserConfig().Git.MainBranches, gui.os.Cmd), + MainBranches: git_commands.NewMainBranches(gui.c.Common, gui.os.Cmd), }, Modes: &types.Modes{ Filtering: filtering.New(startArgs.FilterPath, ""),