MCPcopy
hub / github.com/github/git-sizer / CleanGitEnv

Function CleanGitEnv

internal/testutils/repoutils.go:117–139  ·  view source on GitHub ↗

CleanGitEnv returns a clean environment for running `git` commands so that they won't be affected by the local environment.

()

Source from the content-addressed store, hash-verified

115// CleanGitEnv returns a clean environment for running `git` commands
116// so that they won't be affected by the local environment.
117func CleanGitEnv() []string {
118 osEnv := os.Environ()
119 env := make([]string, 0, len(osEnv)+3)
120 for _, e := range osEnv {
121 i := strings.IndexByte(e, '=')
122 if i == -1 {
123 // This shouldn't happen, but if it does,
124 // ignore it.
125 continue
126 }
127 k := e[:i]
128 if localEnvVars[k] {
129 continue
130 }
131 env = append(env, e)
132 }
133 return append(
134 env,
135 fmt.Sprintf("HOME=%s", os.DevNull),
136 fmt.Sprintf("XDG_CONFIG_HOME=%s", os.DevNull),
137 "GIT_CONFIG_NOSYSTEM=1",
138 )
139}
140
141// GitCommand creates an `*exec.Cmd` for running `git` in `repo` with
142// the specified arguments.

Callers 2

InitMethod · 0.85
GitCommandMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected