Skip to content

Commit

Permalink
Add optional username and email fields to repo for commits (#5477)
Browse files Browse the repository at this point in the history
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: pipecd-bot <[email protected]>
  • Loading branch information
Warashi authored and pipecd-bot committed Jan 16, 2025
1 parent 4962734 commit ede7c1f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/git/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ type Worktree interface {
}

type repo struct {
// username and email are used to commit changes.
// these fields are optional, and set in the `setUser` method.
username string
email string

dir string
gitPath string
remote string
Expand Down Expand Up @@ -180,6 +185,12 @@ func (r *repo) CopyToModify(dest string) (Repo, error) {
gitEnvs: r.gitEnvs,
}

if r.username != "" || r.email != "" {
if err := cloned.setUser(context.Background(), r.username, r.email); err != nil {
return nil, fmt.Errorf("failed to set user: %v", err)
}

Check warning on line 191 in pkg/git/repo.go

View check run for this annotation

Codecov / codecov/patch

pkg/git/repo.go#L189-L191

Added lines #L189 - L191 were not covered by tests
}

// because we did a local cloning so set the remote url of origin
if err := cloned.setRemote(context.Background(), r.remote); err != nil {
return nil, err
Expand Down Expand Up @@ -406,6 +417,9 @@ func (r repo) addCommit(ctx context.Context, message string, trailers map[string

// setUser configures username and email for local user of this repo.
func (r *repo) setUser(ctx context.Context, username, email string) error {
r.username = username
r.email = email

if out, err := r.runGitCommand(ctx, "config", "user.name", username); err != nil {
return formatCommandError(err, out)
}
Expand Down

0 comments on commit ede7c1f

Please sign in to comment.