git

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

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

func (c Client) DefaultBranch(ctx context.Context, r Repo) (string, error)

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

func (c Client) Dirty(ctx context.Context, top string) (bool, error)

Dirty reports whether git status lists any change in the worktree, untracked files included and ignored files excluded.

func (Client) MergeState

func (c Client) MergeState(ctx context.Context, r Repo, branch string) (MergeState, error)

MergeState returns the merge state of branch.

func (Client) Top

func (c Client) Top(ctx context.Context, dir string) (string, error)

Top returns the top-level directory of the worktree containing dir, also with a detached HEAD. It fails with NotAGitRepository outside a worktree.

func (Client) Tracked

func (c Client) Tracked(ctx context.Context, top, path string) (bool, error)

Tracked reports whether git tracks path, relative to the worktree top.

func (Client) Worktree

func (c Client) Worktree(ctx context.Context, dir string) (Worktree, error)

Worktree returns the worktree containing dir. It fails with NotAGitRepository outside a worktree and with NoBranch when HEAD is detached.

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

type Repo struct {
	Dir    string
	GitDir string
}

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

func (w Worktree) Linked() bool

Linked reports whether w is a linked worktree of a repository with a main worktree.

func (Worktree) MainTop

func (w Worktree) MainTop() string

MainTop is the main worktree's top-level directory: the one holding the common git directory when that is named .git. It is "" for a bare repository or a common directory elsewhere.

func (Worktree) RepoName

func (w Worktree) RepoName() string

RepoName is the name of the directory holding the common git directory: the main worktree's directory, the same for every worktree.

Jump to

Keyboard shortcuts

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