Skip to content

Commit

Permalink
fix: #895 Image Updater continuously force-pushes new commits when ch…
Browse files Browse the repository at this point in the history
…eckout branch is specified

Signed-off-by: Cheng Fang <[email protected]>
  • Loading branch information
chengfang committed Nov 1, 2024
1 parent 78e925b commit a325229
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions pkg/argocd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
return err
}
}
err = gitC.ShallowFetch(checkOutBranch, 1)
if err != nil {
return err
}

// The push branch is by default the same as the checkout branch, unless
// specified after a : separator git-branch annotation, in which case a
Expand All @@ -196,14 +192,30 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis
if wbc.GitWriteBranch != "" {
logCtx.Debugf("Using branch template: %s", wbc.GitWriteBranch)
pushBranch = TemplateBranchName(wbc.GitWriteBranch, changeList)
if pushBranch != "" {
if pushBranch == "" {
return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch)
}
}

// If the pushBranch already exists in the remote origin, directly use it.
// Otherwise, create the new pushBranch from checkoutBranch
if checkOutBranch != pushBranch {
fetchErr := gitC.ShallowFetch(pushBranch, 1)
if fetchErr != nil {
err = gitC.ShallowFetch(checkOutBranch, 1)
if err != nil {
return err
}
logCtx.Debugf("Creating branch '%s' and using that for push operations", pushBranch)
err = gitC.Branch(checkOutBranch, pushBranch)
if err != nil {
return err
}
} else {
return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch)
}
} else {
err = gitC.ShallowFetch(checkOutBranch, 1)
if err != nil {
return err
}
}

Expand Down

0 comments on commit a325229

Please sign in to comment.