Skip to content

Commit 535e71e

Browse files
committed
refactor(runway): compose the checkout git env from gitexec
runGit in the Runway server's checkout provisioning kept its own copy of the scrubbed-plus-transport environment. Build it through gitexec.Env instead — the same source the merger uses — so provisioning and merging assemble an identical environment from one definition. This also closes a gap the two hand-written copies had already opened: provisioning omitted GIT_ATTR_NOSYSTEM and the no-pager/no-editor settings the merge path sets, so a system gitattributes file could influence the initial checkout but not later merge operations. Both now run under the same scrub set.
1 parent 52db8c8 commit 535e71e

2 files changed

Lines changed: 15 additions & 23 deletions

File tree

service/runway/server/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ go_library(
2828
"//platform/extension/consumergate/noop:go_default_library",
2929
"//platform/extension/messagequeue:go_default_library",
3030
"//platform/extension/messagequeue/mysql:go_default_library",
31+
"//platform/git/exec:go_default_library",
3132
"//runway/controller:go_default_library",
3233
"//runway/controller/dlq:go_default_library",
3334
"//runway/controller/merge:go_default_library",

service/runway/server/checkout.go

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
"go.uber.org/zap"
2828

29+
gitexec "github.com/uber/submitqueue/platform/git/exec"
2930
gitmerger "github.com/uber/submitqueue/runway/extension/merger/git"
3031
)
3132

@@ -190,8 +191,9 @@ func setLocalConfig(checkoutPath, key, value string) error {
190191
}
191192

192193
// runGit invokes the pinned git in dir with an environment scrubbed of ambient
193-
// configuration but retaining what is needed to reach a remote — the same split
194-
// the merger draws, so provisioning and merging authenticate identically.
194+
// configuration but retaining what is needed to reach a remote. It composes that
195+
// environment through gitexec.Env, the same source the merger uses, so
196+
// provisioning and merging authenticate — and behave — identically.
195197
func runGit(ctx context.Context, runtime gitmerger.GitRuntime, dir string, args ...string) ([]byte, error) {
196198
full := append([]string{
197199
"--exec-path=" + runtime.ExecPath,
@@ -200,27 +202,16 @@ func runGit(ctx context.Context, runtime gitmerger.GitRuntime, dir string, args
200202

201203
cmd := exec.CommandContext(ctx, runtime.Executable, full...)
202204
cmd.Dir = dir
203-
cmd.Env = []string{
204-
"HOME=" + filepath.Join(dir, ".submitqueue-git-home"),
205-
"GIT_CONFIG_NOSYSTEM=1",
206-
"GIT_CONFIG_GLOBAL=" + os.DevNull,
207-
"GIT_TERMINAL_PROMPT=0",
208-
"GIT_EXEC_PATH=" + runtime.ExecPath,
209-
"GIT_TEMPLATE_DIR=" + runtime.TemplateDir,
210-
"LC_ALL=C",
211-
"LANG=C",
212-
}
213-
for _, name := range []string{
214-
"PATH", "SSH_AUTH_SOCK", "SSH_AGENT_PID",
215-
"GIT_SSH", "GIT_SSH_COMMAND", "GIT_SSH_VARIANT",
216-
"GIT_SSL_CAINFO", "GIT_SSL_CAPATH", "SSL_CERT_DIR", "SSL_CERT_FILE",
217-
"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY",
218-
"http_proxy", "https_proxy", "no_proxy",
219-
} {
220-
if v, ok := os.LookupEnv(name); ok {
221-
cmd.Env = append(cmd.Env, name+"="+v)
222-
}
223-
}
205+
cmd.Env = gitexec.Env(gitexec.EnvOptions{
206+
Transport: true,
207+
Literal: []string{
208+
"HOME=" + filepath.Join(dir, ".submitqueue-git-home"),
209+
"GIT_EXEC_PATH=" + runtime.ExecPath,
210+
"GIT_TEMPLATE_DIR=" + runtime.TemplateDir,
211+
"LC_ALL=C",
212+
"LANG=C",
213+
},
214+
})
224215

225216
var stdout, stderr bytes.Buffer
226217
cmd.Stdout = &stdout

0 commit comments

Comments
 (0)