mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-05-27 23:08:02 +02:00
Avoid crash when the git command to obtain branches fails
This is probably not a good enough solution, because we only log the error (in RefreshHelper.refreshBranches) and don't communicate it otherwise to users. This is true for all errors that happen during refresh, though.
This commit is contained in:
parent
e6bd9d0ae6
commit
c5a2a56700
@ -72,7 +72,10 @@ func (self *BranchLoader) Load(reflogCommits []*models.Commit,
|
|||||||
onWorker func(func() error),
|
onWorker func(func() error),
|
||||||
renderFunc func(),
|
renderFunc func(),
|
||||||
) ([]*models.Branch, error) {
|
) ([]*models.Branch, error) {
|
||||||
branches := self.obtainBranches()
|
branches, err := self.obtainBranches()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if self.AppState.LocalBranchSortOrder == "recency" {
|
if self.AppState.LocalBranchSortOrder == "recency" {
|
||||||
reflogBranches := self.obtainReflogBranches(reflogCommits)
|
reflogBranches := self.obtainReflogBranches(reflogCommits)
|
||||||
@ -232,16 +235,16 @@ func (self *BranchLoader) GetBaseBranch(branch *models.Branch, mainBranches *Mai
|
|||||||
return split[0], nil
|
return split[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BranchLoader) obtainBranches() []*models.Branch {
|
func (self *BranchLoader) obtainBranches() ([]*models.Branch, error) {
|
||||||
output, err := self.getRawBranches()
|
output, err := self.getRawBranches()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
trimmedOutput := strings.TrimSpace(output)
|
trimmedOutput := strings.TrimSpace(output)
|
||||||
outputLines := strings.Split(trimmedOutput, "\n")
|
outputLines := strings.Split(trimmedOutput, "\n")
|
||||||
|
|
||||||
return lo.FilterMap(outputLines, func(line string, _ int) (*models.Branch, bool) {
|
branches := lo.FilterMap(outputLines, func(line string, _ int) (*models.Branch, bool) {
|
||||||
if line == "" {
|
if line == "" {
|
||||||
return nil, false
|
return nil, false
|
||||||
}
|
}
|
||||||
@ -257,6 +260,7 @@ func (self *BranchLoader) obtainBranches() []*models.Branch {
|
|||||||
storeCommitDateAsRecency := self.AppState.LocalBranchSortOrder != "recency"
|
storeCommitDateAsRecency := self.AppState.LocalBranchSortOrder != "recency"
|
||||||
return obtainBranch(split, storeCommitDateAsRecency), true
|
return obtainBranch(split, storeCommitDateAsRecency), true
|
||||||
})
|
})
|
||||||
|
return branches, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (self *BranchLoader) getRawBranches() (string, error) {
|
func (self *BranchLoader) getRawBranches() (string, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user