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

Function cmdGit

script/ghmock/gitcmd.go:238–304  ·  view source on GitHub ↗
(args []string, stdout, stderr io.Writer)

Source from the content-addressed store, hash-verified

236}
237
238func cmdGit(args []string, stdout, stderr io.Writer) error {
239 opts, err := parseGitArgs(args)
240 if err != nil {
241 return err
242 }
243 st, err := openState()
244 if err != nil {
245 return err
246 }
247 world, err := st.gitWorld(opts)
248 if err != nil {
249 return err
250 }
251 dir, err := gitWorkDir(world, opts.in)
252 if err != nil {
253 return err
254 }
255 ca, err := newCertAuthority()
256 if err != nil {
257 return err
258 }
259 scratch, err := newScratch(ca)
260 if err != nil {
261 return err
262 }
263 defer os.RemoveAll(scratch)
264 backend := &gitBackend{world: world, scratch: scratch}
265 srv, err := startServer(st, nil, ca, backend)
266 if err != nil {
267 return err
268 }
269 defer srv.close()
270 env, err := gitEnvironment(ghEnv(scratch, srv.proxyURL(), runOptions{}), scratch, world)
271 if err != nil {
272 return err
273 }
274 ctx, cancel := context.WithTimeout(context.Background(), opts.timeout)
275 defer cancel()
276 env = gitDeadlineEnvironment(ctx, env)
277 cmd := exec.CommandContext(ctx, "git", opts.args...)
278 cmd.Dir, cmd.Env = dir, env
279 cmd.Stdin = strings.NewReader(opts.stdin)
280 var out, diagnostic bytes.Buffer
281 cmd.Stdout = io.MultiWriter(stdout, &out)
282 cmd.Stderr = io.MultiWriter(stderr, &diagnostic)
283 containCommand(cmd, false)
284 runErr := cmd.Run()
285 requests, err := gitRequests(scratch, srv.close())
286 if err != nil {
287 return err
288 }
289 record := gitCommandRecord{
290 In: opts.in, Args: opts.args, Stdin: opts.stdin, ExitCode: processExitCode(runErr),
291 Stdout: hideDirectory(out.String(), world, "<git>"),
292 Stderr: hideDirectory(diagnostic.String(), world, "<git>"), Requests: requests,
293 }
294 if err := appendJSONL(filepath.Join(world, "commands.jsonl"), []gitCommandRecord{record}); err != nil {
295 return err

Callers 3

TestCmdGitFunction · 0.85
gitForTestFunction · 0.85
runMainFunction · 0.85

Calls 15

parseGitArgsFunction · 0.85
openStateFunction · 0.85
gitWorkDirFunction · 0.85
newCertAuthorityFunction · 0.85
newScratchFunction · 0.85
startServerFunction · 0.85
gitEnvironmentFunction · 0.85
ghEnvFunction · 0.85
gitDeadlineEnvironmentFunction · 0.85
gitRequestsFunction · 0.85
processExitCodeFunction · 0.85
hideDirectoryFunction · 0.85

Tested by 2

TestCmdGitFunction · 0.68
gitForTestFunction · 0.68