Documentation
¶
Overview ¶
Package gitx is the binary's one door to git: reads mirror the shell-outs bin/f10-load-project.sh makes, the semantics oracle, so the two stay comparable. 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 CommitTree(ctx context.Context, dir, tree string, parents []string, message ...string) (string, error)
- func Config(ctx context.Context, dir, key string) (string, error)
- func CurrentBranch(ctx context.Context, dir string) string
- func DeleteBranch(ctx context.Context, dir, branch string) error
- func DeleteRemoteRef(ctx context.Context, dir, branch string) error
- func Diverged(err error) bool
- func Fetch(ctx context.Context, dir string) error
- func FetchCommit(ctx context.Context, dir, sha string) error
- func FetchInto(ctx context.Context, dir, branch string) error
- func FetchRef(ctx context.Context, dir, refspec string) error
- func Integrate(ctx context.Context, dir, method, base, upstream string, message ...string) (bool, error)
- func IsAncestor(ctx context.Context, dir, commit, ref string) (bool, error)
- func Markers(ctx context.Context, dir, base string) ([]string, error)
- func MergeBase(ctx context.Context, dir, a, b string) (string, error)
- func MergeTree(ctx context.Context, dir, base, head string) (string, error)
- func MergesCleanly(ctx context.Context, dir, base, head string) (bool, error)
- func Out(ctx context.Context, dir string, args ...string) string
- func PullFF(ctx context.Context, dir string) error
- func Push(ctx context.Context, dir, branch, lease string) error
- func Read(ctx context.Context, dir string, args ...string) (string, bool, error)
- func Ref(ctx context.Context, dir, ref string) (string, error)
- func RefLocked(err error) bool
- func Refs(ctx context.Context, dir string, patterns ...string) ([]string, error)
- func RemoteBranchExists(ctx context.Context, dir, branch string) (bool, error)
- func RemoteBranches(ctx context.Context, dir string) (map[string]string, error)
- func RemoveWorktree(ctx context.Context, dir, path string) error
- func Resolved(p string) string
- func SamePath(a, b string) bool
- func SetConfig(ctx context.Context, dir, key, value string) error
- func StaleRef(err error) bool
- func Status(ctx context.Context, dir string) ([]string, error)
- func Switch(ctx context.Context, dir, branch string) error
- func TrackBranch(ctx context.Context, dir, branch string, force bool) error
- func UnknownObject(err error) bool
- func Unmerged(ctx context.Context, dir string) ([]string, error)
- func UnsetConfig(ctx context.Context, dir, key string) error
- func UpdateRef(ctx context.Context, dir, ref, sha, old string) error
- type Cherry
- type ConfigEntry
- type Conflict
- type ExitError
- type Operation
- 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 exit, ok := errors.AsType[*exec.ExitError](err); ok && ctx.Err() == nil { return "", &ExitError{ Args: args, Code: exit.ExitCode(), Stdout: strings.TrimSpace(string(out)), Stderr: strings.TrimSpace(stderr.String()), } } 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 non-zero exit is an *ExitError carrying git's own stderr, which names the cause better than any wrapper could, and the code, which Read needs.
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 CommitTree ¶ added in v0.42.0
func CommitTree(ctx context.Context, dir, tree string, parents []string, message ...string) (string, error)
CommitTree writes a commit of tree on parents with a message of one paragraph per part, and returns its sha. No ref moves.
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. The branch's config section goes with it.
func DeleteRemoteRef ¶ added in v0.33.0
DeleteRemoteRef drops the local copy of origin's branch, which a branch deleted through the host's API leaves behind until a pruning fetch. git deletes a ref that is not there without complaint.
func Diverged ¶ added in v0.55.0
Diverged reports whether git refused a fast-forward because the local branch holds commits its upstream lacks.
func FetchCommit ¶ added in v0.48.0
FetchCommit brings one commit over from origin by sha: a request's head after its branch was deleted there, which GitHub and GitLab still serve.
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 FetchRef ¶ added in v0.48.0
FetchRef fetches one ref from origin into FETCH_HEAD: a closed request's head, which no branch holds once its branch is deleted.
func Integrate ¶ added in v0.55.0
func Integrate(ctx context.Context, dir, method, base, upstream string, message ...string) (bool, error)
Integrate brings base into the checked-out branch: merge (message one -m per part), rebase, or onto, which replays only the commits past upstream. A stop on conflicts is stopped, not an error: the merge or rebase stays in progress for whoever settles it.
func IsAncestor ¶
IsAncestor reports whether commit is reachable from ref: git answers with exit 0 or 1. An unknown object is a no too, since a recorded sha may name a commit squashed away; anything else is an error.
func Markers ¶ added in v0.55.0
Markers lists the paths the branch changes since base that still hold a conflict marker line. Only <<<<<<< and >>>>>>> count: a bare ======= is a markdown heading underline as often as a marker.
func MergeBase ¶ added in v0.49.0
MergeBase is the best common ancestor of a and b, or "" when they share none.
func MergeTree ¶ added in v0.42.0
MergeTree is the tree of head merged into base, built in memory as MergesCleanly tries it; a conflict is an error.
func MergesCleanly ¶ added in v0.33.0
MergesCleanly tries the merge in memory, nothing checked out or written. git exits 1 both for a conflict (on stdout) and for a ref it cannot merge (on stderr), which is an error. Not --quiet: git 2.56 exits 0 with it.
func Out ¶
Out runs git and returns trimmed stdout, or "" on any error. It cannot tell "not there" from "git failed", so it is for display only: a read that decides what f10 does next goes through Read.
func PullFF ¶
PullFF fast-forwards the checked-out branch from its upstream, and fails rather than merge when it cannot.
func Push ¶ added in v0.33.0
Push sends HEAD to origin's branch. A lease (the sha origin had when the caller read it) forces the push only while origin still has it, which a rebased branch needs; "" pushes a fast-forward and nothing else.
func Read ¶ added in v0.46.0
Read runs a quiet git read: exit 0 is the value, exit 1 absent with no error, anything else the error. A form whose "not there" exits 128 (a rev-parse --verify without -q) reads absence as an error, which halts.
func RefLocked ¶ added in v0.55.0
RefLocked reports whether git failed for want of a ref's lock. A stale ref says the same words, but no wait clears it (StaleRef).
func Refs ¶
Refs lists the refs matching for-each-ref patterns as branch names, `refs/heads/` and `refs/remotes/` stripped. The full refname is asked for since git shortens to `heads/x` when a tag shares the name.
func RemoteBranchExists ¶
RemoteBranchExists asks origin whether it still has branch, which is the one git read here that reaches the network.
func RemoteBranches ¶ added in v0.45.0
RemoteBranches is every branch origin has, name to tip sha, in one network read. A checkout with no origin has none.
func RemoveWorktree ¶
RemoveWorktree removes the checkout at path. A dirty tree makes git refuse, which callers rule out first.
func Resolved ¶ added in v0.46.0
Resolved is the path with symlinks resolved. A component that does not exist - a removed or never-created path - keeps its name below the longest prefix that does, so two spellings of one place still compare.
func SamePath ¶ added in v0.46.0
SamePath compares two worktree paths with symlinks resolved where they exist.
func SetConfig ¶
SetConfig writes one local config entry. Local config never leaves the machine, which makes it the place for a per-branch fact in stealth mode.
func StaleRef ¶ added in v0.55.0
StaleRef reports whether git failed on a remote-tracking ref that only `git remote prune origin` removes.
func Status ¶
Status lists `status --porcelain`'s lines, empty for a clean tree. Ignored files are not listed, so an excluded .f10/ never counts.
func Switch ¶ added in v0.35.0
Switch checks out branch in dir. A dirty tree can make git refuse, which callers rule out first.
func TrackBranch ¶ added in v0.35.0
TrackBranch creates local branch tracking origin's of the same name, so a pull or push in its worktree needs no upstream set. force moves an existing branch there, which git refuses while a worktree has it checked out.
func UnknownObject ¶ added in v0.48.0
UnknownObject reports git refusing a sha the clone does not have.
func Unmerged ¶ added in v0.55.0
Unmerged lists the paths a stopped merge or rebase left conflicted.
func UnsetConfig ¶
UnsetConfig removes one entry from the repository's local config.
Types ¶
type Cherry ¶ added in v0.48.0
type Cherry struct {
SHA, Subject string
}
A Cherry is a commit whose patch another ref lacks, as `git cherry` lists it.
func Unlanded ¶ added in v0.48.0
Unlanded lists the commits on head beyond limit whose patch upstream lacks, oldest first. `git cherry` matches by patch id, so a change that landed by squash or rebase is found, and skips merge commits; a head behind limit has none. A limit the clone lacks is an UnknownObject error.
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, error)
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.
type Conflict ¶ added in v0.47.0
A Conflict is one path a merge would conflict on, with the blob each stage brought (1 the merge base, 2 base's side, 3 head's side, "" where a side lacks the path); two on a path are the same only when their blobs are.
type ExitError ¶ added in v0.46.0
An ExitError is git having run and exited non-zero. Stdout is what git printed before exiting, for the reads whose exit 1 carries an answer (merge-tree names the conflicting files that way).
type Operation ¶ added in v0.55.0
type Operation struct {
Kind string // "merge", "rebase", or "" for none
Onto string
Done, Total int
}
An Operation is a merge or a rebase in progress. Onto is the other side: the merged commit, or the commit a rebase replays onto. Done and Total count a rebase's commits, 0 where git does not say.