Documentation
¶
Overview ¶
Package gitrun is the one runner for a one-shot git child.
Every git this repository starts for an answer goes through here: it is bounded by the caller's context or by a named default (subproc.GitBudget, 60 s; subproc.GitLongBudget, 300 s for a command that goes to the network), it carries WaitDelay so a killed git cannot hang its caller on the pipe that git's own child (an ssh, a credential helper, a pager) holds open, and it reports a kill as a *subproc.TimeoutError. The environment is the caller's choice: a caller that scrubs it passes the scrubbed list in Options.Env, and a caller that must leave it intact (a hook that was handed GIT_INDEX_FILE) leaves Env nil. A caller whose repository is the one it names with C (a tool reading its own store while a git that called it exported GIT_DIR) sets OwnRepo, which drops the variables that say where a repository is.
Index ¶
- Constants
- Variables
- func Combined(ctx context.Context, o Options, args ...string) ([]byte, error)
- func Command(ctx context.Context, o Options, args ...string) (*exec.Cmd, context.CancelFunc)
- func Output(ctx context.Context, o Options, args ...string) (string, error)
- func Prepare(ctx context.Context, o Options, args ...string) subproc.Bounded
- func WithoutRepoVars(env []string) []string
- type Error
- type Options
- type Result
Constants ¶
const DefaultTimeout = subproc.GitBudget
DefaultTimeout is how long one local git may run when the caller's context has no sooner deadline and Options.Timeout is zero; a network command gets subproc.GitLongBudget (see subproc.GitBudgetFor).
Variables ¶
var RepoVars = []string{
"GIT_DIR", "GIT_WORK_TREE", "GIT_OBJECT_DIRECTORY", "GIT_ALTERNATE_OBJECT_DIRECTORIES",
"GIT_INDEX_FILE", "GIT_COMMON_DIR", "GIT_NAMESPACE", "GIT_PREFIX", "GIT_CEILING_DIRECTORIES",
}
RepoVars are the variables with which git is told where a repository, its objects, its index or its work tree are. A git that starts a helper (a credential helper, a hook) exports them, and a git the helper starts reads the helper's repository, not its own.
Functions ¶
func Command ¶
Command builds the git child: -C, directory, environment, deadline and WaitDelay applied, nothing started. The returned cancel is called once the child is waited for.
func Output ¶
Output runs git and returns its stdout with its leading and trailing blanks trimmed. A failure is an *Error (which unwraps to the cause, so a *subproc.TimeoutError is still found).
func Prepare ¶
Prepare is Command for a caller that reads the stream itself and must tell a deadline kill from its own failure: the Bounded carries the bound context, whose subproc.Expired says the deadline ended the child.
func WithoutRepoVars ¶
WithoutRepoVars returns env without the RepoVars; every other entry, GIT_TERMINAL_PROMPT among them, is kept in order. The argument is not changed.
Types ¶
type Error ¶
Error is a failed git as Output reports it: the command, the cause and git's own stderr.
type Options ¶
type Options struct {
// Bin is the git program; empty is "git" on PATH.
Bin string
// C, when set, is passed as `git -C C`.
C string
// Dir, when set, is the child's working directory.
Dir string
// Env is the child's whole environment; nil inherits the caller's.
Env []string
// OwnRepo says the repository is the one C names, whatever the caller's environment
// says: the variables in RepoVars are dropped from the child's environment (Env, or the
// caller's when Env is nil) and every other variable is kept.
OwnRepo bool
// Stdin, when set, is the child's standard input.
Stdin io.Reader
// Timeout overrides the default budget when positive.
Timeout time.Duration
// WaitDelay overrides subproc.WaitDelay when positive.
WaitDelay time.Duration
}
Options is how one git runs.