diff --git a/pkg/argocd/git.go b/pkg/argocd/git.go index 41f7d2e1..f8cf3b3b 100644 --- a/pkg/argocd/git.go +++ b/pkg/argocd/git.go @@ -187,11 +187,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis } } - err = gitC.Checkout(checkOutBranch) - 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 // new branch will be made following a template that can use the list of @@ -207,15 +202,16 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis if err != nil { return err } - err = gitC.Checkout(pushBranch) - if err != nil { - return err - } } else { return fmt.Errorf("Git branch name could not be created from the template: %s", wbc.GitWriteBranch) } } + err = gitC.Checkout(pushBranch) + if err != nil { + return err + } + if err, skip := write(app, wbc, gitC); err != nil { return err } else if skip { diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 6c9a8ac0..8950bdfe 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -1784,9 +1784,6 @@ func Test_CommitUpdates(t *testing.T) { t.Run("Good commit to different than base branch", func(t *testing.T) { gitMock, _, cleanup := mockGit(t) defer cleanup() - gitMock.On("Checkout", mock.Anything).Run(func(args mock.Arguments) { - args.Assert(t, "mydefaultbranch") - }).Return(nil).Once() gitMock.On("Add", mock.Anything).Return(nil) gitMock.On("Branch", mock.Anything, mock.Anything).Return(nil) gitMock.On("Commit", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) @@ -1806,7 +1803,7 @@ func Test_CommitUpdates(t *testing.T) { NewTag: tag.NewImageTag("1.1", time.Now(), ""), }, } - gitMock.On("Checkout", TemplateBranchName(wbc.GitWriteBranch, cl)).Return(nil).Once() + gitMock.On("Checkout", TemplateBranchName(wbc.GitWriteBranch, cl)).Return(nil) err = commitChanges(&app, wbc, cl) assert.NoError(t, err)