Preserve child working directory in environment overlays
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -151,14 +150,15 @@ func newCommand(ctx context.Context, invocation Invocation) (*exec.Cmd, error) {
|
||||
command.Dir = invocation.Dir
|
||||
command.WaitDelay = time.Second
|
||||
if len(invocation.Env) != 0 || len(invocation.UnsetEnv) != 0 {
|
||||
command.Env = environmentEntries(invocation.Env, invocation.UnsetEnv)
|
||||
// Dir contributes PWD on POSIX before explicit overrides are applied.
|
||||
command.Env = environmentEntries(command.Environ(), invocation.Env, invocation.UnsetEnv)
|
||||
}
|
||||
return command, nil
|
||||
}
|
||||
|
||||
func environmentEntries(overlay map[string]string, unset []string) []string {
|
||||
environment := make(map[string]string, len(os.Environ())+len(overlay))
|
||||
for _, entry := range os.Environ() {
|
||||
func environmentEntries(base []string, overlay map[string]string, unset []string) []string {
|
||||
environment := make(map[string]string, len(base)+len(overlay))
|
||||
for _, entry := range base {
|
||||
key, value, ok := strings.Cut(entry, "=")
|
||||
if ok {
|
||||
environment[key] = value
|
||||
|
||||
Reference in New Issue
Block a user