Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherry-pick #5477 #5478

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@
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 @@

// 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
Loading