Documentation
¶
Overview ¶
Package gitexec locates a git binary and composes the environment git runs in. It is the single source of truth for that environment across every SubmitQueue caller — demo tooling, the change provider's repository, and the Runway merger.
The environment has two halves. The scrub set denies git all ambient configuration that could change what a command produces — a global hooks path, a signing requirement, a commit template — which is what makes a scripted run behave the same on every machine. The transport set carries what a command needs to reach a remote — the SSH agent socket, git's ssh and credential helpers on PATH, TLS roots, proxy settings — none of which can change an answer. Every caller shares both halves; they differ only in the literal entries they add (a pinned exec path, an isolated HOME), which is why Env takes those as options rather than baking one caller's policy in.
HOME is deliberately not in the transport set: a caller that isolates HOME and a caller that inherits it disagree, so each supplies it itself.
Index ¶
- func Command(ctx context.Context, git, dir string, args ...string) *exec.Cmd
- func CommandFailure(ctx context.Context, args []string, message string, cause error) error
- func Env(opts EnvOptions) []string
- func Operation(args []string) string
- func Output(ctx context.Context, git, dir string, args ...string) (string, error)
- func Resolve(path string) (string, error)
- func Run(ctx context.Context, git, dir string, args ...string) error
- type CommandError
- type EnvOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Command ¶
Command builds a git invocation in dir with the ambient environment removed. An empty dir runs in the current working directory. PATH is passed so git can find its helpers; nothing else the host sets reaches the command.
func CommandFailure ¶
CommandFailure builds the error for a failed git invocation.
A context that has ended takes precedence over whatever git reported. When os/exec kills a child because its context was cancelled, Wait reports only the death — a bare *exec.ExitError reading "signal: killed" — and neither context.Canceled nor context.DeadlineExceeded appears anywhere in the chain, so nothing downstream can tell an interrupted command apart from one that genuinely failed. Reading ctx.Err() here is the only place that distinction still exists; surfacing it puts cancellation back in the chain where the generic classifier can recognise it.
func Env ¶
func Env(opts EnvOptions) []string
Env composes a git command environment: the scrub set, then the requested variables inherited from the parent (only those actually set, so an unset SSH_AUTH_SOCK stays absent rather than becoming empty), then the literals.
Types ¶
type CommandError ¶
type CommandError struct {
// contains filtered or unexported fields
}
CommandError preserves the failed Git operation and its process error for backend-specific classification after callers add contextual wrapping.
func NewCommandError ¶
func NewCommandError(operation, message string, cause error) *CommandError
NewCommandError records a failed Git operation without assigning retry policy. Callers supply the rendered diagnostic they want Error to expose.
func (*CommandError) Diagnostic ¶
func (e *CommandError) Diagnostic() string
Diagnostic returns Git's rendered failure output.
func (*CommandError) Error ¶
func (e *CommandError) Error() string
Error returns the command diagnostic supplied by the execution boundary.
func (*CommandError) Operation ¶
func (e *CommandError) Operation() string
Operation returns the Git subcommand, such as fetch or cherry-pick.
func (*CommandError) Unwrap ¶
func (e *CommandError) Unwrap() error
Unwrap returns the process error reported by os/exec.
type EnvOptions ¶
type EnvOptions struct {
// Transport inherits the transport variables from the parent when set.
Transport bool
// Passthrough names further variables to inherit from the parent when set.
Passthrough []string
// Literal entries are appended last as "NAME=value", so they override any
// inherited value of the same name.
Literal []string
}
EnvOptions selects what, on top of the always-applied scrub set, a git command's environment carries.