From 990602adc13c6952090138016b8b0a48ac416dd8 Mon Sep 17 00:00:00 2001 From: Cheng Fang Date: Fri, 8 Nov 2024 09:47:10 -0500 Subject: [PATCH] fix: delay setting git.username and git.email config till commit time (#912) Signed-off-by: Cheng Fang --- pkg/argocd/git.go | 16 ++++++++-------- pkg/argocd/update_test.go | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/pkg/argocd/git.go b/pkg/argocd/git.go index 7d30cec3..71422c2e 100644 --- a/pkg/argocd/git.go +++ b/pkg/argocd/git.go @@ -158,14 +158,6 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis return err } - // Set username and e-mail address used to identify the commiter - if wbc.GitCommitUser != "" && wbc.GitCommitEmail != "" { - err = gitC.Config(wbc.GitCommitUser, wbc.GitCommitEmail) - if err != nil { - return err - } - } - // The branch to checkout is either a configured branch in the write-back // config, or taken from the application spec's targetRevision. If the // target revision is set to the special value HEAD, or is the empty @@ -247,6 +239,14 @@ func commitChangesGit(app *v1alpha1.Application, wbc *WriteBackConfig, changeLis defer os.Remove(cm.Name()) } + // Set username and e-mail address used to identify the commiter + if wbc.GitCommitUser != "" && wbc.GitCommitEmail != "" { + err = gitC.Config(wbc.GitCommitUser, wbc.GitCommitEmail) + if err != nil { + return err + } + } + if wbc.GitCommitSigningKey != "" { commitOpts.SigningKey = wbc.GitCommitSigningKey } diff --git a/pkg/argocd/update_test.go b/pkg/argocd/update_test.go index 416de5d3..1bd1d3e2 100644 --- a/pkg/argocd/update_test.go +++ b/pkg/argocd/update_test.go @@ -3363,6 +3363,7 @@ replacements: [] app := app.DeepCopy() gitMock := &gitmock.Client{} gitMock.On("Init").Return(nil) + gitMock.On("Root").Return(t.TempDir()) gitMock.On("ShallowFetch", mock.Anything, mock.Anything).Return(nil) gitMock.On("Checkout", mock.Anything, mock.Anything).Run(func(args mock.Arguments) { args.Assert(t, "mydefaultbranch", false)