diff options
| author | Cheng Fang <cfang@redhat.com> | 2024-11-01 13:39:19 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-11-01 13:39:19 -0400 |
| commit | 17a57daf29b63ebca92d4285783dc3cf6698f190 (patch) | |
| tree | 403a0487e0225a858cf1a1e083b539cc9d51a8ac /pkg/argocd/git.go | |
| parent | 78e925b9e8cc9352119f31d5903903c2c82a25e3 (diff) | |
fix: #895 Image Updater continuously force-pushes new commits when checkout branch is specified (#911)
Signed-off-by: Cheng Fang <cfang@redhat.com>
Diffstat (limited to 'pkg/argocd/git.go')
| -rw-r--r-- | pkg/argocd/git.go | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/pkg/argocd/git.go b/pkg/argocd/git.go index 13e62b6..7d30cec 100644 --- a/pkg/argocd/git.go +++ b/pkg/argocd/git.go @@ -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 @@ -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 } } |
