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

Set environment when running git commands #3103

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions private/buf/cmd/buf/command/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func getGitMetadataUploadOptions(
if err := validateInputIsValidDirAndGitCheckout(ctx, runner, container, input); err != nil {
return nil, err
}
uncommittedFiles, err := git.CheckForUncommittedGitChanges(ctx, runner, input)
uncommittedFiles, err := git.CheckForUncommittedGitChanges(ctx, runner, container, input)
if err != nil {
return nil, err
}
Expand All @@ -457,7 +457,7 @@ func getGitMetadataUploadOptions(
}
return nil, err
}
currentGitCommit, err := git.GetCurrentHEADGitCommit(ctx, runner, input)
currentGitCommit, err := git.GetCurrentHEADGitCommit(ctx, runner, container, input)
if err != nil {
return nil, err
}
Expand Down
6 changes: 6 additions & 0 deletions private/pkg/git/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,13 @@ func CheckDirectoryIsValidGitCheckout(
func CheckForUncommittedGitChanges(
ctx context.Context,
runner command.Runner,
envContainer app.EnvContainer,
dir string,
) ([]string, error) {
stdout := bytes.NewBuffer(nil)
stderr := bytes.NewBuffer(nil)
var modifiedFiles []string
envMap := app.EnvironMap(envContainer)
// Unstaged changes
if err := runner.Run(
ctx,
Expand All @@ -260,6 +262,7 @@ func CheckForUncommittedGitChanges(
command.RunWithStdout(stdout),
command.RunWithStderr(stderr),
command.RunWithDir(dir),
command.RunWithEnv(envMap),
); err != nil {
return nil, fmt.Errorf("failed to get unstaged changes: %w: %s", err, stderr.String())
}
Expand All @@ -275,6 +278,7 @@ func CheckForUncommittedGitChanges(
command.RunWithStdout(stdout),
command.RunWithStderr(stderr),
command.RunWithDir(dir),
command.RunWithEnv(envMap),
); err != nil {
return nil, fmt.Errorf("failed to get staged changes: %w: %s", err, stderr.String())
}
Expand All @@ -287,6 +291,7 @@ func CheckForUncommittedGitChanges(
func GetCurrentHEADGitCommit(
ctx context.Context,
runner command.Runner,
envContainer app.EnvContainer,
dir string,
) (string, error) {
stdout := bytes.NewBuffer(nil)
Expand All @@ -298,6 +303,7 @@ func GetCurrentHEADGitCommit(
command.RunWithStdout(stdout),
command.RunWithStderr(stderr),
command.RunWithDir(dir),
command.RunWithEnv(app.EnvironMap(envContainer)),
); err != nil {
return "", fmt.Errorf("failed to get current HEAD commit: %w: %s", err, stderr.String())
}
Expand Down
7 changes: 5 additions & 2 deletions private/pkg/git/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,16 @@ func getRemote(
hostname, repositoryPath, err := getRemoteURLMetadata(
ctx,
runner,
envContainer,
dir,
name,
)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get remote URL metadata: %w", err)
}
headBranch, err := getRemoteHEADBranch(ctx, runner, envContainer, dir, name)
if err != nil {
return nil, err
return nil, fmt.Errorf("failed to get remote HEAD branch: %w", err)
}
return newRemote(
name,
Expand Down Expand Up @@ -185,6 +186,7 @@ func validateRemoteExists(
func getRemoteURLMetadata(
ctx context.Context,
runner command.Runner,
envContainer app.EnvContainer,
dir string,
remote string,
) (string, string, error) {
Expand All @@ -199,6 +201,7 @@ func getRemoteURLMetadata(
command.RunWithStdout(stdout),
command.RunWithStderr(stderr),
command.RunWithDir(dir),
command.RunWithEnv(app.EnvironMap(envContainer)),
); err != nil {
return "", "", err
}
Expand Down