Skip to content

Commit

Permalink
Check branch existence before merge
Browse files Browse the repository at this point in the history
We now support merges happenning between stage and release. But the code
for this does not currently check to see if the remote branch exists
before attempting to fetch and merge.

This commit modifies the git pusher to check if the remote branch exists
before merging.

Signed-off-by: Adolfo García Veytia (Puerco) <adolfo.garcia@uservers.net>
  • Loading branch information
puerco committed Jul 21, 2021
1 parent 9a707f8 commit 167a681
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions pkg/release/push_git_objects.go
Expand Up @@ -248,6 +248,19 @@ func (gp *GitObjectPusher) mergeRemoteIfRequired(branch string) error {
return errors.Wrap(err, "fetch remote")
}

branchExists, err := gp.repo.HasRemoteBranch(branch)
if err != nil {
return errors.Wrapf(
err, "checking if branch %s exists in repo remote", branch,
)
}
if !branchExists {
logrus.Infof(
"Git repository does not have remote branch %s, not attempting merge", branch,
)
return nil
}

logrus.Infof("Merging %s branch", branch)
if err := gp.repo.Merge(branch); err != nil {
return errors.Wrapf(
Expand Down

0 comments on commit 167a681

Please sign in to comment.