MCPcopy Create free account
hub / github.com/cli/cli / ghEnv

Function ghEnv

script/ghmock/run.go:525–580  ·  view source on GitHub ↗

ghEnv builds gh's whole environment from scratch, so the caller's tokens, config and git settings never reach it. Every run gets fresh directories, so an alias or extension added in one run is gone in the next.

(scratch, proxyURL string, opts runOptions)

Source from the content-addressed store, hash-verified

523// config and git settings never reach it. Every run gets fresh directories,
524// so an alias or extension added in one run is gone in the next.
525func ghEnv(scratch, proxyURL string, opts runOptions) []string {
526 dir := func(name string) string { return filepath.Join(scratch, name) }
527 env := []string{
528 "PATH=" + os.Getenv("PATH"),
529 "HOME=" + dir("home"),
530 "TMPDIR=" + dir("tmp"),
531 "GH_CONFIG_DIR=" + dir("config"),
532 "XDG_CONFIG_HOME=" + dir("home/.config"),
533 "XDG_DATA_HOME=" + dir("home/.local/share"),
534 "XDG_STATE_HOME=" + dir("home/.local/state"),
535 "XDG_CACHE_HOME=" + dir("home/.cache"),
536 "HTTP_PROXY=" + proxyURL,
537 "HTTPS_PROXY=" + proxyURL,
538 "http_proxy=" + proxyURL,
539 "https_proxy=" + proxyURL,
540 "NO_PROXY=",
541 "no_proxy=",
542 "GH_NO_UPDATE_NOTIFIER=1",
543 "GH_NO_EXTENSION_UPDATE_NOTIFIER=1",
544 "GH_TELEMETRY=disabled",
545 "GH_SPINNER_DISABLED=1",
546 "GH_PAGER=cat",
547 "PAGER=cat",
548 "GH_BROWSER=echo",
549 "BROWSER=echo",
550 "GH_EDITOR=true",
551 "EDITOR=true",
552 "VISUAL=true",
553 "GIT_TERMINAL_PROMPT=0",
554 "GIT_CONFIG_NOSYSTEM=1",
555 "GIT_CONFIG_GLOBAL=" + dir("home/.gitconfig"),
556 }
557 if opts.localhost {
558 env = append(env, "GH_HOST="+mockHost)
559 } else {
560 // gh and git trust only ghmock's authority, so they can't complete a
561 // TLS handshake with a real host.
562 env = append(env,
563 "SSL_CERT_FILE="+dir(caFile),
564 "SSL_CERT_DIR="+dir("certs"),
565 "GIT_SSL_CAINFO="+dir(caFile),
566 )
567 }
568 if !opts.terminal {
569 // Without a terminal, a prompt would wait for input that never comes.
570 env = append(env, "GH_PROMPT_DISABLED=1")
571 }
572 if opts.tty {
573 env = append(env, "GH_FORCE_TTY=120")
574 }
575 if opts.tty || opts.terminal {
576 // Like most terminals, so gh colors its output as it would for a user.
577 env = append(env, "TERM=xterm-256color", "COLORTERM=truecolor")
578 }
579 return env
580}
581
582func ghVersion(path string, env []string, dir string) string {

Callers 4

serveGitHTTPMethod · 0.85
runBinaryFunction · 0.85
cmdRepoFunction · 0.85
cmdGitFunction · 0.85

Calls 1

JoinMethod · 0.80

Tested by

no test coverage detected