gitexec

package
v0.3.0-20260914181346-... Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 14, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(ctx context.Context, git, dir string, args ...string) *exec.Cmd

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

func CommandFailure(ctx context.Context, args []string, message string, cause error) error

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.

func Operation

func Operation(args []string) string

Operation returns the Git subcommand in args, or "" when args is empty.

func Output

func Output(ctx context.Context, git, dir string, args ...string) (string, error)

Output executes a git command and returns its trimmed stdout.

func Resolve

func Resolve(path string) (string, error)

Resolve returns an absolute path to a git binary.

Preference order is the supplied path, then GIT_EXECUTABLE, then PATH — the same convention the Runway server's runtime resolution follows, so a deployment or a Bazel target can pin git without the caller knowing which did.

func Run

func Run(ctx context.Context, git, dir string, args ...string) error

Run executes a git command and discards its output, reporting stderr in the error so a failure says what git said rather than only that it exited.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL