Documentation
¶
Overview ¶
Package git answers what siding needs to know about a worktree by running the git CLI: where it is, which branch it is on, and whether removing its stack's data could lose work.
Index ¶
- type Client
- func (c Client) DefaultBranch(ctx context.Context, r Repo) (string, error)
- func (c Client) Dirty(ctx context.Context, top string) (bool, error)
- func (c Client) MergeState(ctx context.Context, r Repo, branch string) (MergeState, error)
- func (c Client) Top(ctx context.Context, dir string) (string, error)
- func (c Client) Tracked(ctx context.Context, top, path string) (bool, error)
- func (c Client) Worktree(ctx context.Context, dir string) (Worktree, error)
- type MergeState
- type Repo
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// Binary is the git executable; empty means "git" from PATH.
Binary string
}
Client runs git.
func (Client) DefaultBranch ¶
DefaultBranch returns the ref the repository merges into: what origin/HEAD points to, else a local main, else a local master. It returns "" when there is none.
func (Client) Dirty ¶
Dirty reports whether git status lists any change in the worktree, untracked files included and ignored files excluded.
func (Client) MergeState ¶
MergeState returns the merge state of branch.
func (Client) Top ¶
Top returns the top-level directory of the worktree containing dir, also with a detached HEAD. It fails with NotAGitRepository outside a worktree.
type MergeState ¶
type MergeState struct {
// Base is the default branch's ref, "" when there is none.
Base string
// Exists is false when the branch itself is gone.
Exists bool
// Ancestor: the branch's tip is contained in Base.
Ancestor bool
// AtBase: the branch's tip is Base's tip, so Base has not moved past it.
AtBase bool
// UpstreamGone: the branch tracked a remote branch that no longer exists, as after a merged
// pull request whose branch was deleted and pruned (a squash merge included).
UpstreamGone bool
// IsBase: the branch is the default branch itself.
IsBase bool
}
MergeState is what git knows about whether a branch's work has arrived in the default branch.
func (MergeState) BaseName ¶
func (m MergeState) BaseName() string
BaseName is the default branch's short name, e.g. main for refs/remotes/origin/main.
func (MergeState) Merged ¶
func (m MergeState) Merged() bool
Merged is the rule of down --volumes: the branch's commits are in the default branch, or its upstream is gone.
func (MergeState) MergedForGC ¶
func (m MergeState) MergedForGC() bool
MergedForGC is the stricter rule of gc: not the default branch, and either the default branch has moved past a contained tip or the upstream is gone. A branch without commits of its own, which an agent may just have created, does not count.
type Repo ¶
Repo names a repository for commands that need no worktree: the worktree's directory, or, when the worktree is gone, the common git directory.
type Worktree ¶
type Worktree struct {
// Top is the absolute path of the worktree's top-level directory.
Top string
// CommonDir is the absolute path of the repository's common git directory, the same for
// every worktree of the repository.
CommonDir string
// Branch is the checked-out branch, without refs/heads/.
Branch string
}
Worktree is a git worktree.
func (Worktree) Linked ¶
Linked reports whether w is a linked worktree of a repository with a main worktree.