MCPcopy
hub / github.com/dagger/container-use / RunGitCommand

Function RunGitCommand

repository/git.go:33–53  ·  view source on GitHub ↗

RunGitCommand executes a git command in the specified directory. This is exported for use in tests and other packages that need direct git access.

(ctx context.Context, dir string, args ...string)

Source from the content-addressed store, hash-verified

31// RunGitCommand executes a git command in the specified directory.
32// This is exported for use in tests and other packages that need direct git access.
33func RunGitCommand(ctx context.Context, dir string, args ...string) (out string, rerr error) {
34 slog.Info(fmt.Sprintf("[%s] $ git %s", dir, strings.Join(args, " ")))
35 defer func() {
36 slog.Info(fmt.Sprintf("[%s] $ git %s (DONE)", dir, strings.Join(args, " ")), "err", rerr)
37 }()
38
39 cmd := exec.CommandContext(ctx, "git", args...)
40 cmd.Dir = dir
41
42 output, err := cmd.CombinedOutput()
43 if err != nil {
44 var exitErr *exec.ExitError
45 if errors.As(err, &exitErr) {
46 return "", fmt.Errorf("git command failed (exit code %d): %w\nOutput: %s",
47 exitErr.ExitCode(), err, string(output))
48 }
49 return "", fmt.Errorf("git command failed: %w", err)
50 }
51
52 return string(output), nil
53}
54
55// RunInteractiveGitCommand executes a git command in the specified directory in interactive mode.
56func RunInteractiveGitCommand(ctx context.Context, dir string, w io.Writer, args ...string) (rerr error) {

Callers 15

WithRepositoryFunction · 0.92
gitCommitFunction · 0.92
GitCommandMethod · 0.92
TestRepositoryCheckoutFunction · 0.92
TestRepositoryMergeFunction · 0.92
TestRepositoryApplyFunction · 0.92
TestGitAuditTrailFunction · 0.92
TestEnvironmentIsolationFunction · 0.92

Calls 1

InfoMethod · 0.80

Tested by 15

TestRepositoryCheckoutFunction · 0.74
TestRepositoryMergeFunction · 0.74
TestRepositoryApplyFunction · 0.74
TestGitAuditTrailFunction · 0.74
TestEnvironmentIsolationFunction · 0.74
TestWeirdUserScenariosFunction · 0.74
TestEnvironmentSelectionFunction · 0.74
TestRepositoryOpenFunction · 0.68