Skip to content

Commit

Permalink
don't panic on git rebase error
Browse files Browse the repository at this point in the history
commit-id:9835a0a8
  • Loading branch information
ejoffe authored and Eitan Joffe committed Nov 19, 2021
1 parent 7ec988d commit 3439ad3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion git/mockgit/mockgit.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ type responder interface {

func (m *Mock) ExpectFetch() {
m.expect("git fetch")
m.expect("git rebase origin/master --autostash")
m.expect("git rebase origin/master --autostash").respond("")
}

func (m *Mock) ExpectLogAndRespond(commits []*git.Commit) {
Expand Down
23 changes: 11 additions & 12 deletions spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"regexp"
"strconv"
"strings"
"sync"

"github.com/ejoffe/profiletimer"
"github.com/ejoffe/spr/config"
Expand Down Expand Up @@ -87,6 +86,9 @@ func (sd *stackediff) AmendCommit(ctx context.Context) {
func (sd *stackediff) UpdatePullRequests(ctx context.Context) {
sd.profiletimer.Step("UpdatePullRequests::Start")
githubInfo := sd.fetchAndGetGitHubInfo(ctx)
if githubInfo == nil {
return
}
sd.profiletimer.Step("UpdatePullRequests::FetchAndGetGitHubInfo")
localCommits := sd.getLocalCommitStack()
sd.profiletimer.Step("UpdatePullRequests::GetLocalCommitStack")
Expand Down Expand Up @@ -367,20 +369,17 @@ func commitsReordered(localCommits []git.Commit, pullRequests []*github.PullRequ
}

func (sd *stackediff) fetchAndGetGitHubInfo(ctx context.Context) *github.GitHubInfo {
var waitgroup sync.WaitGroup
waitgroup.Add(1)

fetch := func() {
sd.mustgit("fetch", nil)
rebaseCommand := fmt.Sprintf("rebase %s/%s --autostash",
sd.config.Repo.GitHubRemote, sd.config.Repo.GitHubBranch)
sd.mustgit(rebaseCommand, nil)
waitgroup.Done()
sd.mustgit("fetch", nil)
rebaseCommand := fmt.Sprintf("rebase %s/%s --autostash",
sd.config.Repo.GitHubRemote, sd.config.Repo.GitHubBranch)
var output string
err := sd.gitcmd.Git(rebaseCommand, &output)
if err != nil {
fmt.Fprintln(sd.output, output)
return nil
}

go fetch()
info := sd.github.GetInfo(ctx, sd.gitcmd)
waitgroup.Wait()

return info
}
Expand Down

0 comments on commit 3439ad3

Please sign in to comment.