Skip to content

Commit

Permalink
don't panic for stash and rebase git errors
Browse files Browse the repository at this point in the history
commit-id:2bd9c1ae
  • Loading branch information
ejoffe authored and Eitan Joffe committed Dec 6, 2021
1 parent 926b9a6 commit 43cc143
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 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").respond("")
m.expect("git rebase origin/master --autostash")
}

func (m *Mock) ExpectLogAndRespond(commits []*git.Commit) {
Expand Down
17 changes: 11 additions & 6 deletions spr/spr.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ func (sd *stackediff) UpdatePullRequests(ctx context.Context) {
sd.profiletimer.Step("UpdatePullRequests::ReparentPullRequestsToMaster")
}

sd.syncCommitStackToGitHub(ctx, localCommits, githubInfo)
if !sd.syncCommitStackToGitHub(ctx, localCommits, githubInfo) {
return
}
sd.profiletimer.Step("UpdatePullRequests::SyncCommitStackToGithub")

type prUpdate struct {
Expand Down Expand Up @@ -379,10 +381,9 @@ func (sd *stackediff) fetchAndGetGitHubInfo(ctx context.Context) *github.GitHubI
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)
//var output string
err := sd.gitcmd.Git(rebaseCommand, nil)
if err != nil {
fmt.Fprintln(sd.output, output)
return nil
}

Expand All @@ -395,12 +396,15 @@ func (sd *stackediff) fetchAndGetGitHubInfo(ctx context.Context) *github.GitHubI
// which are new (on top of remote branch) and creates a corresponding
// branch on github for each commit.
func (sd *stackediff) syncCommitStackToGitHub(ctx context.Context,
commits []git.Commit, info *github.GitHubInfo) {
commits []git.Commit, info *github.GitHubInfo) bool {

var output string
sd.mustgit("status --porcelain --untracked-files=no", &output)
if output != "" {
sd.mustgit("stash", nil)
err := sd.gitcmd.Git("stash", nil)
if err != nil {
return false
}
defer sd.mustgit("stash pop", nil)
}

Expand Down Expand Up @@ -435,6 +439,7 @@ func (sd *stackediff) syncCommitStackToGitHub(ctx context.Context,
sd.mustgit(pushCommand, nil)
}
sd.profiletimer.Step("SyncCommitStack::PushBranches")
return true
}

func (sd *stackediff) branchNameFromCommit(info *github.GitHubInfo, commit git.Commit) string {
Expand Down

0 comments on commit 43cc143

Please sign in to comment.