Skip to content

Commit

Permalink
fix: delay setting git.username and git.email config till commit time (
Browse files Browse the repository at this point in the history
…#912)

Signed-off-by: Cheng Fang <[email protected]>
  • Loading branch information
chengfang authored Nov 8, 2024
1 parent 8146cf1 commit 1924339
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/argocd/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/argocd/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1924339

Please sign in to comment.