diff --git a/pkg/commands/git_commands/branch_loader.go b/pkg/commands/git_commands/branch_loader.go index 3053cd6fa..6cb61754f 100644 --- a/pkg/commands/git_commands/branch_loader.go +++ b/pkg/commands/git_commands/branch_loader.go @@ -74,7 +74,10 @@ func (self *BranchLoader) Load(reflogCommits []*models.Commit, onWorker func(func() error), renderFunc func(), ) ([]*models.Branch, error) { - branches, tips := self.obtainBranches() + branches, tips, err := self.obtainBranches() + if err != nil { + return nil, err + } switch self.UserConfig().Git.LocalBranchSortOrder { case "date": @@ -326,10 +329,10 @@ func (self *BranchLoader) GetBaseBranch(branch *models.Branch, mainBranches *Mai // Returns the branches, along with the tip of each of them, keyed by full ref // name -func (self *BranchLoader) obtainBranches() ([]*models.Branch, map[string]refTip) { +func (self *BranchLoader) obtainBranches() ([]*models.Branch, map[string]refTip, error) { output, err := self.getRawBranches() if err != nil { - panic(err) + return nil, nil, err } trimmedOutput := strings.TrimSpace(output) @@ -355,7 +358,7 @@ func (self *BranchLoader) obtainBranches() ([]*models.Branch, map[string]refTip) return branch, true }) - return branches, tips + return branches, tips, nil } func (self *BranchLoader) getRawBranches() (string, error) { diff --git a/pkg/commands/git_commands/branch_loader_test.go b/pkg/commands/git_commands/branch_loader_test.go index eee277ca3..ad9c0b48f 100644 --- a/pkg/commands/git_commands/branch_loader_test.go +++ b/pkg/commands/git_commands/branch_loader_test.go @@ -179,11 +179,8 @@ func TestLoadWhenListingBranchesFails(t *testing.T) { cmd: gitCommon.cmd, } - /* EXPECTED: _, err := loader.Load(nil, nil, nil, false, nil, nil) assert.EqualError(t, err, "chdir /path/to/repo: no such file or directory") - ACTUAL: */ - assert.PanicsWithError(t, "chdir /path/to/repo: no such file or directory", func() { _, _ = loader.Load(nil, nil, nil, false, nil, nil) }) runner.CheckForMissingCalls() }