{"modulePath":"github.com/DomBlack/git-stack","version":"v0.5.0","isLatest":true,"isStandardLibrary":false,"goos":"linux","goarch":"amd64","docs":"# package exec\n\nPackage exec runs subprocesses. Every subprocess git-stack starts goes through a Runner so that output capture, TTY hand-off, cancellation and debug logging are handled in exactly one place.\n\nCapture mode is the default: stdout and stderr are buffered and stdin is whatever the caller supplies (never the parent's stdin). Passthrough mode attaches the real terminal and is only available to runners built with WithTTY; the MCP server never constructs such a runner.\n\nA runner without a TTY also keeps its children away from the terminal the process happens to have been started from: they run in their own session (no controlling terminal, so /dev/tty cannot be opened), git's terminal prompts are disabled and GPG\\_TTY is dropped. Otherwise a passphrase or credential prompt from ssh-keygen, gpg or git would wait on a terminal nobody is watching, which is how the MCP server used to hang.\n\n## Variables\n\n```go\nvar ErrTTYUnavailable = errors.New(\"exec: passthrough mode requested but no terminal is attached\")\n```\nErrTTYUnavailable is returned when Passthrough mode is requested from a runner that has no terminal attached.\n\n## Functions\n\n```go\nfunc BuildEnv(base, extra, unset []string) []string\n```\nBuildEnv returns base with the keys in unset removed and extra appended. Later entries win when git or the OS reads the environment, so extra effectively overrides base.\n\n## Types\n\n```go\ntype Cmd struct {\n\tName string\n\tArgs []string\n\t// Dir is the working directory; empty means the current directory.\n\tDir string\n\t// Env holds KEY=VALUE pairs appended to the parent environment.\n\tEnv []string\n\t// Unset lists environment keys removed before Env is applied.\n\tUnset []string\n\t// Stdin is fed to the process in Capture mode. Nil means no input.\n\tStdin io.Reader\n\t// Stream, when set in Capture mode, also receives the process's stderr as\n\t// it is produced so progress from a long backend command can be relayed\n\t// live. Stderr is still captured in the Result. Ignored in Passthrough.\n\tStream io.Writer\n\tMode   Mode\n}\n```\nCmd describes a subprocess to run.\n\n```go\nfunc (c Cmd) String() string\n```\nString renders the command line for logs and error messages.\n\n```go\ntype ExitError struct {\n\tCmd    Cmd\n\tResult Result\n}\n```\nExitError reports a non-zero exit status.\n\n```go\nfunc (e *ExitError) Error() string\n```\n\n```go\ntype Mode int\n```\nMode selects how a subprocess's standard streams are wired.\n\n```go\nconst (\n\t// Capture buffers stdout and stderr (default).\n\tCapture Mode = iota\n\t// Passthrough attaches the runner's TTY to stdin, stdout and stderr.\n\tPassthrough\n)\n```\n\n```go\nfunc (m Mode) String() string\n```\n\n```go\ntype NotFoundError struct {\n\tName string\n}\n```\nNotFoundError reports that the executable is not on PATH.\n\n```go\nfunc (e *NotFoundError) Error() string\n```\n\n```go\ntype Option func(*runner)\n```\nOption configures a Runner.\n\n```go\nfunc WithDebug(w io.Writer) Option\n```\nWithDebug logs every command (name, arguments, directory, mode, exit code and duration) to w. Stdin contents are never logged.\n\n```go\nfunc WithTTY(t TTY) Option\n```\nWithTTY enables Passthrough mode using the given terminal files.\n\n```go\ntype Result struct {\n\tStdout   []byte\n\tStderr   []byte\n\tExitCode int\n\tDuration time.Duration\n}\n```\nResult is the outcome of a finished subprocess.\n\n```go\nfunc (r Result) Err() string\n```\nErr returns stderr with surrounding whitespace trimmed.\n\n```go\nfunc (r Result) Out() string\n```\nOut returns stdout with surrounding whitespace trimmed.\n\n```go\ntype Runner interface {\n\t// Run executes c and waits for it. A non-zero exit status is returned as\n\t// *ExitError (the Result is still populated). A missing executable is\n\t// returned as *NotFoundError. Context cancellation is returned as the\n\t// context's error.\n\tRun(ctx context.Context, c Cmd) (Result, error)\n}\n```\nRunner runs subprocesses.\n\n```go\nfunc New(opts ...Option) Runner\n```\nNew returns a Runner backed by os/exec.\n\n```go\ntype TTY struct {\n\tIn, Out, Err *os.File\n}\n```\nTTY holds the terminal files used for Passthrough mode.\n\n","path":"github.com/DomBlack/git-stack/pkg/exec","name":"exec","synopsis":"Package exec runs subprocesses.","isRedistributable":true}
