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

Function runBinary

script/ghmock/run.go:280–400  ·  view source on GitHub ↗

runBinary runs one gh binary in its own scratch folder. With ca, gh uses github.com and trusts only ca; without it, gh uses github.localhost.

(st *state, chk *checker, binary string, opts runOptions, ca *certAuthority, gitDir, configDir string)

Source from the content-addressed store, hash-verified

278// runBinary runs one gh binary in its own scratch folder. With ca, gh uses
279// github.com and trusts only ca; without it, gh uses github.localhost.
280func runBinary(st *state, chk *checker, binary string, opts runOptions, ca *certAuthority, gitDir, configDir string) (runResult, error) {
281 path, err := resolveBinary(binary)
282 if err != nil {
283 return runResult{}, err
284 }
285
286 scratch, err := newScratch(ca)
287 if err != nil {
288 return runResult{}, err
289 }
290 defer os.RemoveAll(scratch)
291 workDir := filepath.Join(scratch, "work")
292 host := mockHost
293 if ca != nil {
294 host = dotcomHost
295 }
296 if err := writeGHConfig(filepath.Join(scratch, "config"), host, !opts.loggedOut); err != nil {
297 return runResult{}, err
298 }
299
300 var backend *gitBackend
301 if gitDir != "" {
302 backend = &gitBackend{world: filepath.Join(st.dir, filepath.FromSlash(gitDir)), scratch: scratch}
303 workDir, err = gitWorkDir(backend.world, opts.in)
304 if err != nil {
305 return runResult{}, err
306 }
307 }
308 srv, err := startServer(st, chk, ca, backend)
309 if err != nil {
310 return runResult{}, err
311 }
312 defer srv.close()
313 env := ghEnv(scratch, srv.proxyURL(), opts)
314 res := runResult{path: path, version: ghVersion(path, env, workDir)}
315 configPath := ""
316 if configDir != "" {
317 configPath, err = filepath.Abs(filepath.Join(st.dir, filepath.FromSlash(configDir)))
318 if err != nil {
319 return runResult{}, err
320 }
321 // Version discovery uses the default scratch config so it cannot
322 // migrate or modify the fixture before the requested command runs.
323 for i, value := range env {
324 if strings.HasPrefix(value, "GH_CONFIG_DIR=") {
325 env[i] = "GH_CONFIG_DIR=" + configPath
326 }
327 }
328 res.config = &configOutcome{Directory: configDir}
329 }
330 if backend != nil {
331 env, err = gitEnvironment(env, scratch, backend.world)
332 if err != nil {
333 return runResult{}, err
334 }
335 version, err := localGit(workDir, env, "--version")
336 if err != nil {
337 return runResult{}, err

Callers 1

runAllFunction · 0.85

Calls 15

resolveBinaryFunction · 0.85
newScratchFunction · 0.85
writeGHConfigFunction · 0.85
gitWorkDirFunction · 0.85
startServerFunction · 0.85
ghEnvFunction · 0.85
ghVersionFunction · 0.85
gitEnvironmentFunction · 0.85
localGitFunction · 0.85
gitDeadlineEnvironmentFunction · 0.85
hideDirectoryFunction · 0.85
hideScratchFunction · 0.85

Tested by

no test coverage detected