Documentation
¶
Overview ¶
Package git is a thin wrapper over the git CLI. It is the only place in tbd that shells out to git; every other package works through these primitives so behavior is easy to test against throwaway repositories.
Index ¶
- func NowRFC3339() string
- type Commit
- type GraphCommit
- type GraphRef
- type Repo
- func (r *Repo) AheadBehind(a, b string) (ahead, behind int, err error)
- func (r *Repo) BranchCreate(name, start string) error
- func (r *Repo) BranchCreateForce(name, start string) error
- func (r *Repo) BranchDelete(name string) error
- func (r *Repo) BranchesContaining(sha string) []string
- func (r *Repo) Checkout(ref string) error
- func (r *Repo) CheckoutCreate(name, start string) error
- func (r *Repo) CherryPick(ref string) error
- func (r *Repo) CherryPickAbort() error
- func (r *Repo) CherryPickContinue() error
- func (r *Repo) CherryPickInProgress() bool
- func (r *Repo) Commit(msg string) error
- func (r *Repo) CommitAmend(msg string) error
- func (r *Repo) CommitInteractive(amend bool, seed string) error
- func (r *Repo) CommitOf(ref string) string
- func (r *Repo) CommitTree(tree, msg string) (string, error)
- func (r *Repo) CommitterName(ref string) string
- func (r *Repo) ConfigGet(key string) string
- func (r *Repo) ConfigSet(key, value string) error
- func (r *Repo) ConflictingBranch(branch string) (string, bool)
- func (r *Repo) CurrentBranch() (string, error)
- func (r *Repo) DecoratedGraph(limit int) (string, error)
- func (r *Repo) DeleteRef(name string) error
- func (r *Repo) EmptyTree() (string, error)
- func (r *Repo) Exists(ref string) bool
- func (r *Repo) FFMerge(ref string) error
- func (r *Repo) Fetch(remote string) error
- func (r *Repo) FetchTags(remote string) error
- func (r *Repo) FullMessage(ref string) string
- func (r *Repo) GitDir() (string, error)
- func (r *Repo) GraphCommits(limit int) ([]GraphCommit, error)
- func (r *Repo) GraphRefs() ([]GraphRef, error)
- func (r *Repo) HasRemote(remote string) bool
- func (r *Repo) HasStaged() bool
- func (r *Repo) IsAncestor(a, b string) bool
- func (r *Repo) IsClean() (bool, error)
- func (r *Repo) ListBranches(pattern string) ([]string, error)
- func (r *Repo) ListTags(pattern string) ([]string, error)
- func (r *Repo) LogRange(revRange string) ([]Commit, error)
- func (r *Repo) MergeBase(a, b string) (string, error)
- func (r *Repo) PushBranch(remote, branch string) error
- func (r *Repo) PushBranchCAS(remote, branch, expected string) error
- func (r *Repo) PushBranchForce(remote, branch string) error
- func (r *Repo) PushDeleteBranch(remote, branch string) error
- func (r *Repo) PushDeleteRef(remote, ref string) error
- func (r *Repo) PushDeleteTag(remote, tag string) error
- func (r *Repo) PushRefCAS(remote, ref, expected string) error
- func (r *Repo) PushTag(remote, tag string) error
- func (r *Repo) PushTagCAS(remote, tag, expectedOld string) error
- func (r *Repo) PushTagForce(remote, tag string) error
- func (r *Repo) Rebase(onto string) error
- func (r *Repo) RebaseAbort() error
- func (r *Repo) RebaseContinue() error
- func (r *Repo) RebaseInProgress() bool
- func (r *Repo) RefMessage(ref string) string
- func (r *Repo) RefSha(ref string) string
- func (r *Repo) ReflogContains(branch, sha string) bool
- func (r *Repo) RemoteBranchSha(remote, branch string) string
- func (r *Repo) RemoteHasBranch(remote, branch string) bool
- func (r *Repo) RemoteRefSha(remote, ref string) string
- func (r *Repo) RemoteTagSha(remote, tag string) string
- func (r *Repo) ResetHard(ref string) error
- func (r *Repo) ResetSoft(ref string) error
- func (r *Repo) RevList(args ...string) ([]string, error)
- func (r *Repo) RevParse(ref string) (string, error)
- func (r *Repo) RevertNoEdit(ref string) error
- func (r *Repo) Root() (string, error)
- func (r *Repo) Short(ref string) (string, error)
- func (r *Repo) StageAll() error
- func (r *Repo) Subject(ref string) string
- func (r *Repo) TagAnnotated(name, ref, msg string) error
- func (r *Repo) TagDelete(name string) error
- func (r *Repo) TagInfo(name string) (TagDetail, bool)
- func (r *Repo) TagLightweight(name, ref string) error
- func (r *Repo) UnmergedPaths() ([]string, error)
- func (r *Repo) UpdateRef(name, value string) error
- func (r *Repo) ValidBranchName(branch string) bool
- func (r *Repo) ValidTagName(tag string) bool
- type TagDetail
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NowRFC3339 ¶
func NowRFC3339() string
NowRFC3339 exists so callers can use one timestamp format consistently for git-visible metadata.
Types ¶
type GraphCommit ¶ added in v2.1.0
type GraphCommit struct {
SHA string
Short string
Parents []string
Author string
Email string
Unix int64
Subject string
}
GraphCommit is a commit node with enough metadata for a browser visualizer.
type GraphRef ¶ added in v2.1.0
GraphRef is a git ref resolved to the commit it points at. For annotated tags, Target is the peeled object rather than the tag object.
type Repo ¶
type Repo struct{ Dir string }
Repo binds a working directory so callers need not repeat it.
func (*Repo) AheadBehind ¶
AheadBehind returns how many commits a is ahead of and behind b.
func (*Repo) BranchCreate ¶
BranchCreate creates a branch at start without checking it out.
func (*Repo) BranchCreateForce ¶
BranchCreateForce creates or moves a local branch to start.
func (*Repo) BranchDelete ¶
BranchDelete removes a local branch (force).
func (*Repo) BranchesContaining ¶
BranchesContaining returns the local branches whose history includes sha.
func (*Repo) CheckoutCreate ¶
CheckoutCreate creates and switches to a new branch at start.
func (*Repo) CherryPick ¶
CherryPick replays ref's commit onto the current branch, keeping its message.
func (*Repo) CherryPickAbort ¶
CherryPickAbort cancels an in-progress cherry-pick.
func (*Repo) CherryPickContinue ¶
CherryPickContinue resumes a stopped cherry-pick without opening an editor.
func (*Repo) CherryPickInProgress ¶
CherryPickInProgress reports whether a cherry-pick stopped on a conflict.
func (*Repo) CommitAmend ¶
CommitAmend folds staged changes into the current commit. An empty msg keeps the existing message; otherwise it replaces it. --allow-empty so a pure re-sync (no staged changes) still succeeds.
func (*Repo) CommitInteractive ¶
CommitInteractive makes a commit that opens the user's editor for the message, inheriting the terminal. With amend it rewords/folds into the current commit; a non-empty seed pre-fills the editor (used when squashing, to start from the kept message).
func (*Repo) CommitTree ¶
CommitTree creates an orphan commit with msg and returns its object id.
func (*Repo) CommitterName ¶
CommitterName returns the committer name of ref's tip ("" on error).
func (*Repo) ConflictingBranch ¶
ConflictingBranch returns an existing local branch that would block creating branch because of git's directory/file ref layout: you cannot have both "a/b" (a file) and "a" or "a/b/c" (a needs "a/" to be a directory). It returns the conflicting branch and true, or "" and false when branch is creatable.
func (*Repo) CurrentBranch ¶
CurrentBranch returns the checked-out branch name, erroring on detached HEAD.
func (*Repo) DecoratedGraph ¶
DecoratedGraph returns a compact decorated graph with all refs. It is meant as raw material for tbd's richer horizon views.
func (*Repo) FetchTags ¶
FetchTags updates local tags from the remote, overwriting moved ones so lease status reflects the authoritative remote position.
func (*Repo) FullMessage ¶
FullMessage returns ref's complete commit message ("" on error).
func (*Repo) GitDir ¶
GitDir returns the absolute path to this repository's .git directory, used to stash tbd's own per-repo state (e.g. a pending operation to resume).
func (*Repo) GraphCommits ¶ added in v2.1.0
func (r *Repo) GraphCommits(limit int) ([]GraphCommit, error)
GraphCommits returns commits reachable from HEAD and all refs, newest first in topological order. Parent SHAs are full-length IDs so callers can build edges without depending on git-log's ASCII graph output.
func (*Repo) GraphRefs ¶ added in v2.1.0
GraphRefs returns local branches, remote-tracking branches, tags, stash, and tbd-owned refs. Missing namespaces are not errors.
func (*Repo) IsAncestor ¶
IsAncestor reports whether a is an ancestor of (or equal to) b. This is the core invariant primitive.
func (*Repo) ListBranches ¶
ListBranches returns local branch names matching pattern (glob, e.g. "feature/*"). An empty result is not an error.
func (*Repo) PushBranch ¶
PushBranch pushes a local branch to remote (never forced; trunk must fast-forward).
func (*Repo) PushBranchCAS ¶
PushBranchCAS publishes a branch with --force-with-lease using an explicit expected remote value (empty means "expect the branch to be absent"), setting upstream. Force is required because tbd rewrites feature history on every commit; the explicit lease makes it a true compare-and-swap that survives a preceding fetch, so a teammate's push is never clobbered.
func (*Repo) PushBranchForce ¶
PushBranchForce publishes a branch with an unconditional force (the escape hatch when the lease check is in the way).
func (*Repo) PushDeleteBranch ¶
PushDeleteBranch deletes a branch on the remote.
func (*Repo) PushDeleteRef ¶
PushDeleteRef removes any remote ref.
func (*Repo) PushDeleteTag ¶
PushDeleteTag deletes a remote tag.
func (*Repo) PushRefCAS ¶
PushRefCAS publishes a local ref to the same remote ref name using an explicit compare-and-swap value. expected may be empty when the remote ref is expected not to exist.
func (*Repo) PushTagCAS ¶
PushTagCAS pushes a tag using compare-and-swap: the push succeeds only if the remote tag is still at expectedOld (use "" when the tag should not yet exist). This is the sole mutual-exclusion primitive a lease relies on.
func (*Repo) PushTagForce ¶
PushTagForce pushes a tag with an unconditional force (the escape hatch when tag-push is set to "force" or :force is passed).
func (*Repo) RebaseAbort ¶
RebaseAbort cancels an in-progress rebase (best effort).
func (*Repo) RebaseContinue ¶
RebaseContinue resumes a stopped rebase without opening an editor (the existing commit message is kept).
func (*Repo) RebaseInProgress ¶
RebaseInProgress reports whether a rebase is currently stopped (e.g. waiting on conflict resolution).
func (*Repo) RefMessage ¶
RefMessage returns the full commit message at ref, or "" when ref is absent or not a commit.
func (*Repo) RefSha ¶
RefSha returns the raw object sha a ref points at, without peeling (so an annotated tag yields the tag object, which is what --force-with-lease compares against). Returns "" when the ref does not exist.
func (*Repo) ReflogContains ¶
ReflogContains reports whether branch's reflog ever pointed at sha. This is how we recognize a commit that used to be on the working branch before an amend or rebase rewrote it (a now-orphaned "ours"). Best effort: the reflog is local and expires.
func (*Repo) RemoteBranchSha ¶
RemoteBranchSha returns the sha the remote currently has for a branch, or "" if the remote does not have it.
func (*Repo) RemoteHasBranch ¶
RemoteHasBranch reports whether the remote currently has the named branch.
func (*Repo) RemoteRefSha ¶
RemoteRefSha returns the raw sha the remote currently has for ref.
func (*Repo) RemoteTagSha ¶
RemoteTagSha returns the raw sha the remote has for tag, or "" if absent.
func (*Repo) ResetSoft ¶
ResetSoft moves HEAD to ref while keeping the index and working tree, so the combined content can be re-committed as one.
func (*Repo) RevertNoEdit ¶
RevertNoEdit reverts ref into the current branch using git's default revert message. The caller is responsible for ensuring the working tree is clean.
func (*Repo) TagAnnotated ¶
TagAnnotated creates or moves an annotated tag at ref, recording msg. The tagger identity (git config user) becomes the lease holder record.
func (*Repo) TagLightweight ¶
TagLightweight creates or moves a lightweight tag at ref.
func (*Repo) UnmergedPaths ¶
UnmergedPaths lists files that still have unresolved conflicts.
func (*Repo) ValidBranchName ¶
ValidBranchName reports whether branch is a well-formed git branch name (no spaces, control chars, "..", trailing "/", etc.), per git check-ref-format. branch is the full branch name (e.g. "feature/login"); it is validated as the ref "refs/heads/<branch>" so leading-dash and @{...} components are rejected rather than reinterpreted.
func (*Repo) ValidTagName ¶
ValidTagName reports whether tag is a well-formed git tag name, per git check-ref-format (validated as "refs/tags/<tag>").