Skip to content

Commit 876bd29

Browse files
Add optional username and email fields to repo for commits (#5477) (#5478)
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]> Signed-off-by: pipecd-bot <[email protected]> Co-authored-by: Shinnosuke Sawada-Dazai <[email protected]>
1 parent 4962734 commit 876bd29

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/git/repo.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ type Worktree interface {
6565
}
6666

6767
type repo struct {
68+
// username and email are used to commit changes.
69+
// these fields are optional, and set in the `setUser` method.
70+
username string
71+
email string
72+
6873
dir string
6974
gitPath string
7075
remote string
@@ -180,6 +185,12 @@ func (r *repo) CopyToModify(dest string) (Repo, error) {
180185
gitEnvs: r.gitEnvs,
181186
}
182187

188+
if r.username != "" || r.email != "" {
189+
if err := cloned.setUser(context.Background(), r.username, r.email); err != nil {
190+
return nil, fmt.Errorf("failed to set user: %v", err)
191+
}
192+
}
193+
183194
// because we did a local cloning so set the remote url of origin
184195
if err := cloned.setRemote(context.Background(), r.remote); err != nil {
185196
return nil, err
@@ -406,6 +417,9 @@ func (r repo) addCommit(ctx context.Context, message string, trailers map[string
406417

407418
// setUser configures username and email for local user of this repo.
408419
func (r *repo) setUser(ctx context.Context, username, email string) error {
420+
r.username = username
421+
r.email = email
422+
409423
if out, err := r.runGitCommand(ctx, "config", "user.name", username); err != nil {
410424
return formatCommandError(err, out)
411425
}

0 commit comments

Comments
 (0)