Skip to content

Commit

Permalink
Fix outdated update always creating pull request to master
Browse files Browse the repository at this point in the history
  • Loading branch information
davegaeddert committed Oct 2, 2019
1 parent 68f4540 commit 0b710ec
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions internal/runner/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ func CI(autoconfigure bool, types []string) error {

for _, update := range outdatedUpdates {
output.Event("Updating outdated update: %s", update.title)
if err := runUpdate(update, update.branch, update.branch, true); err != nil {
// TODO if update.branch already exists, maybe base could be
// determined from what it originally branched off of?
if err := runUpdate(update, startingBranch, update.branch, true); err != nil {
failedUpdates = append(failedUpdates, &updateResult{
update: update,
err: err,
Expand Down Expand Up @@ -189,19 +191,18 @@ func getCurrentBranch(ci ci.CIProvider) string {
return branch
}

func runUpdate(update *Update, base, head string, allowEmpty bool) error {
git.Checkout(base)

if base == head {
// PR back to the main branch
// (setting or env var?)
base = "master"
func runUpdate(update *Update, base, head string, existingUpdate bool) error {
if existingUpdate {
// go straight to it
git.Checkout(head)
} else {
// create a branch for it
git.Checkout(base)
git.Branch(head)
}

defer func() {
// Theres should only be uncommitted changes if we're bailing early
// There should only be uncommitted changes if we're bailing early
git.ResetAndClean()
git.CheckoutLast()
}()
Expand All @@ -217,7 +218,7 @@ func runUpdate(update *Update, base, head string, allowEmpty bool) error {
}

if !git.IsDirty() {
if allowEmpty {
if existingUpdate {
output.Event("No new changes to commit")
return nil
}
Expand Down

0 comments on commit 0b710ec

Please sign in to comment.