Skip to content

Commit

Permalink
Fix issue when remote branch is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperMalachowski committed Oct 18, 2024
1 parent ff5349f commit 4a93124
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pkg/github/bumper/bumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,13 @@ func gitPush(remote, remoteBranch, baseBranch string, repo *git.Repository, auth
}

// Get the remote head commit
var remoteRefHash plumbing.Hash
remoteRef, err := repo.Reference(plumbing.NewRemoteReferenceName(forkRemoteName, remoteBranch), true)
if err != nil {
// Ignore the error if the remote branch does not exist
if err != nil && err != plumbing.ErrReferenceNotFound {
return fmt.Errorf("get remote reference: %w", err)
} else {
remoteRefHash = remoteRef.Hash()
}

// Get the local head commit
Expand All @@ -127,13 +131,13 @@ func gitPush(remote, remoteBranch, baseBranch string, repo *git.Repository, auth
}

// Check if the remote head commit is the same as the local head commit
if remoteRef.Hash() == localRef.Hash() {
if remoteRefHash == localRef.Hash() {
logrus.Info("Remote is up to date, quitting.")
return nil
}

if dryrun {
logrus.Infof("[Dryrun] Pushing to %s %s", remote, remoteRef.Name())
logrus.Infof("[Dryrun] Pushing to %s refs/heads/%s", remote, remoteBranch)
return nil
}

Expand Down

0 comments on commit 4a93124

Please sign in to comment.