summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorCheng Fang <cfang@redhat.com>2024-11-08 09:47:10 -0500
committerGitHub <noreply@github.com>2024-11-08 09:47:10 -0500
commit192433988b13a46a8f8c5f4001f26c0fbdec05aa (patch)
tree5a799908bdb0598af2bc949434ee8772324d2952 /pkg
parent8146cf1c31b64009604e763d035aa13d595fb39f (diff)
fix: delay setting git.username and git.email config till commit time (#912)
Signed-off-by: Cheng Fang <cfang@redhat.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/argocd/git.go16
-rw-r--r--pkg/argocd/update_test.go1
2 files changed, 9 insertions, 8 deletions
diff --git a/pkg/argocd/git.go b/pkg/argocd/git.go
index 7d30cec..71422c2 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 416de5d..1bd1d3e 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)