From 3439ad3203909fd7e0357913b3abe884c8ad3112 Mon Sep 17 00:00:00 2001 From: Eitan Joffe Date: Thu, 18 Nov 2021 22:53:30 -0800 Subject: [PATCH] don't panic on git rebase error commit-id:9835a0a8 --- git/mockgit/mockgit.go | 2 +- spr/spr.go | 23 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/git/mockgit/mockgit.go b/git/mockgit/mockgit.go index 40a3e4d..08adb04 100644 --- a/git/mockgit/mockgit.go +++ b/git/mockgit/mockgit.go @@ -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) { diff --git a/spr/spr.go b/spr/spr.go index 6a1e620..d04cf49 100644 --- a/spr/spr.go +++ b/spr/spr.go @@ -9,7 +9,6 @@ import ( "regexp" "strconv" "strings" - "sync" "github.com/ejoffe/profiletimer" "github.com/ejoffe/spr/config" @@ -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") @@ -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 }