Documentation
¶
Overview ¶
Package gitx is the binary's one door to git. The reads mirror the shell-outs bin/resolve.sh makes - the bash script is the semantics oracle, and shelling out identically keeps the two comparable. The writes are `f10 start`'s - a branch, a worktree, and the config entries that record what a branch depends on - and `f10 finish`'s, which undoes them once the branch has merged: the pull, the worktree removal, the branch deletion.
Everything goes through Exec, a variable so a test can answer git without a checkout. No go-git.
Index ¶
- Variables
- func AddWorktree(ctx context.Context, dir, path, branch, base string, create bool) error
- func CurrentBranch(ctx context.Context, dir string) string
- func DeleteBranch(ctx context.Context, dir, branch string) error
- func FetchInto(ctx context.Context, dir, branch string) error
- func IsAncestor(ctx context.Context, dir, commit, ref string) bool
- func Out(ctx context.Context, dir string, args ...string) string
- func PullFF(ctx context.Context, dir string) error
- func Refs(ctx context.Context, dir string, patterns ...string) ([]string, error)
- func RemoteBranchExists(ctx context.Context, dir, branch string) (bool, error)
- func RemoveWorktree(ctx context.Context, dir, path string) error
- func SetConfig(ctx context.Context, dir, key, value string) error
- func Status(ctx context.Context, dir string) ([]string, error)
- func UnsetConfig(ctx context.Context, dir, key string) error
- type ConfigEntry
- type Worktree
Constants ¶
This section is empty.
Variables ¶
var Exec = func(ctx context.Context, dir string, args ...string) (string, error) { cmd := exec.CommandContext(ctx, "git", args...) cmd.Dir = dir var stderr strings.Builder cmd.Stderr = &stderr out, err := cmd.Output() if err != nil { if msg := strings.TrimSpace(stderr.String()); msg != "" { return "", fmt.Errorf("git %s: %s", args[0], msg) } return "", fmt.Errorf("git %s: %w", args[0], err) } return strings.TrimSpace(string(out)), nil }
Exec runs git with args in dir and returns trimmed stdout. A failure carries git's own stderr, which names the cause better than any wrapper could. It is a variable so tests can script answers instead of running git.
Functions ¶
func AddWorktree ¶
AddWorktree checks branch out at path. With create, the branch is made from base - git's HEAD when base is "" - and must not exist yet; otherwise it must.
func CurrentBranch ¶
CurrentBranch is the branch dir has checked out, or "" when detached.
func DeleteBranch ¶
DeleteBranch deletes the local branch whether or not git sees it as merged: a squash or rebase merge leaves no trace git recognises, so the caller's proof is the host's, not git's. The branch's config section goes with it.
func FetchInto ¶
FetchInto updates local branch from origin's branch of the same name without touching the checkout: git fast-forwards a branch that is not checked out and refuses anything else.
func IsAncestor ¶
IsAncestor reports whether commit is reachable from ref. git answers with its exit code, so any failure reads as "no".
func Out ¶
Out runs git and returns trimmed stdout, or "" on any error - absence is a valid result everywhere a read uses it.
func PullFF ¶
PullFF fast-forwards the checked-out branch from its upstream, and fails rather than merge when it cannot.
func Refs ¶
Refs lists the refs matching patterns, in git's own order, as branch names: `refs/heads/` and `refs/remotes/` stripped, so a remote branch reads `origin/x`. The full refname is asked for rather than the short one, which git disambiguates to `heads/x` when a tag shares the name. A pattern is what for-each-ref takes: a literal ref, which also matches everything under it at a slash, or a glob.
func RemoteBranchExists ¶
RemoteBranchExists asks origin whether it still has branch, which is the one git read here that reaches the network.
func RemoveWorktree ¶
RemoveWorktree removes the checkout at path. A dirty tree makes git refuse, which callers rule out first.
func SetConfig ¶
SetConfig writes one entry to the repository's local config, replacing any value the key held. Local config never leaves the machine, which is what makes it the place for a per-branch fact in stealth mode.
Types ¶
type ConfigEntry ¶
A ConfigEntry is one key and its value as `config --get-regexp` lists them.
func ConfigEntries ¶
func ConfigEntries(ctx context.Context, dir, pattern string) []ConfigEntry
ConfigEntries lists the local config entries whose key matches pattern, in git's order. No match is an empty list, not an error: git exits 1 for it, and absence is a valid answer here.