exec

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package exec provides the shared subprocess-runner interface used by the rest of the codebase to invoke git, gh, and tmux without binding production call sites to os/exec directly. Tests inject fakes; production uses Default.

It also owns the constructors for every git and gh subprocess: GitCommand (forces only git's message language to C, so the English stderr callers match on is what git actually prints, while the user's character set and other locale categories reach the hooks and filters git spawns) and GhCommand (runs gh with prompts and the update notifier disabled). TestNoRawGitGhExec fails on any raw exec.Command("git"|"gh", …) in production code outside command.go. tmux has its own constructor, session/tmux.Command, enforced the same way.

Kept as a leaf package so every layer — cmd/, session/git/, tools/ — can import it without creating a cycle (cmd/ imports session/git/).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GhCommand added in v0.13.0

func GhCommand(ctx context.Context, args ...string) *exec.Cmd

GhCommand builds a gh invocation bound to ctx. Every gh subprocess loom runs is built here (TestNoRawGitGhExec enforces it). loom's gh calls never have a terminal: GH_PROMPT_DISABLED=1 guarantees a would-be prompt fails fast instead of waiting out the deadline, and GH_NO_UPDATE_NOTIFIER=1 keeps the "new release available" check off the network and out of the captured output. gh already skips both without a TTY; the variables pin that rather than relying on gh's detection.

func GitCommand added in v0.13.0

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

GitCommand builds a git invocation bound to ctx. Every git subprocess loom runs is built here (TestNoRawGitGhExec enforces it) so its messages are untranslated: callers classify failures by matching git's English stderr (isBranchAbsentErr, isWorktreeAbsentErr, …) and parse its English output (parseShortStat's "insertion"/"deletion"), and a user's non-English locale would otherwise silently misclassify both. Only the message language is forced (see gitEnv); the character set, collation and every other locale category stay the user's, because hooks, filters and credential helpers that git spawns inherit this environment and some (Ruby hooks, for one) break under an ASCII LC_CTYPE.

A non-empty dir is passed as `git -C dir`; "" adds nothing and git runs in the process working directory (or c.Dir, if the caller sets one). The caller's args slice is never modified.

c.Env is always set. A caller that needs extra variables appends them (`c.Env = append(c.Env, "GIT_INDEX_FILE=…")`) rather than rebuilding from os.Environ(), which would drop the locale overrides.

func ToString

func ToString(c *exec.Cmd) string

ToString renders a command for logs in "argv joined by spaces" form.

Types

type Default

type Default struct{}

Default is the production Executor that forwards directly to *exec.Cmd.

func (Default) CombinedOutput

func (Default) CombinedOutput(c *exec.Cmd) ([]byte, error)

func (Default) Output

func (Default) Output(c *exec.Cmd) ([]byte, error)

func (Default) Run

func (Default) Run(c *exec.Cmd) error

type Executor

type Executor interface {
	Run(c *exec.Cmd) error
	Output(c *exec.Cmd) ([]byte, error)
	CombinedOutput(c *exec.Cmd) ([]byte, error)
}

Executor runs *exec.Cmd values. Production callers use Default; tests substitute a recorder or an in-memory fake.

Jump to

Keyboard shortcuts

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