gitx

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package gitx is flow's git plumbing. Every operation is expressed as an explicit argv run through exec.Runner, which is what lets the argv assertions in the tests guarantee flow runs the command the user expects.

Index

Constants

View Source
const ExcludeLine = ".worktrees/"

ExcludeLine is the entry flow adds to info/exclude so the worktrees directory never shows up as an untracked path.

Variables

This section is empty.

Functions

func DirExists

func DirExists(path string) bool

DirExists reports whether path is an existing directory.

func DirIsEmpty

func DirIsEmpty(path string) bool

DirIsEmpty reports whether path is a directory with no entries.

func EnsureExcluded

func EnsureExcluded(commonDir, line string) (added bool, err error)

EnsureExcluded appends line to {git_common_dir}/info/exclude unless it is already present as an exact line, creating the file if needed.

func ParseGitHubRemote

func ParseGitHubRemote(raw string) (owner, name string, ok bool)

ParseGitHubRemote extracts owner and repository from an origin URL. It handles the four shapes git remotes actually come in:

git@github.com:owner/repo.git
ssh://git@github.com/owner/repo.git
https://github.com/owner/repo.git

and each of those without the .git suffix. A non-GitHub remote is not an error — it simply reports false, and GitHub-dependent features degrade.

func ResolvePath

func ResolvePath(p string) string

ResolvePath returns an absolute, symlink-free path. macOS resolves /tmp and /var through symlinks, and git always reports the resolved form, so comparing a user-supplied path against git's output without this produces false mismatches.

func SamePath

func SamePath(a, b string) bool

SamePath reports whether two paths refer to the same location.

Types

type Git

type Git struct {
	Runner flowexec.Runner
	// Dir is the working directory for every invocation.
	Dir string
}

Git runs git commands rooted at a directory.

func New

func New(r flowexec.Runner, dir string) *Git

New returns a Git bound to dir.

func (*Git) AddWorktreeExisting

func (g *Git) AddWorktreeExisting(ctx context.Context, path, branch string) error

AddWorktreeExisting checks out an existing local branch into a new worktree.

func (*Git) AddWorktreeFromBase

func (g *Git) AddWorktreeFromBase(ctx context.Context, path, branch, startPoint string) error

AddWorktreeFromBase creates a new branch off an arbitrary start point.

func (*Git) AddWorktreeTracking

func (g *Git) AddWorktreeTracking(ctx context.Context, path, branch, remote string) error

AddWorktreeTracking creates a branch tracking {remote}/{branch}.

func (*Git) At

func (g *Git) At(dir string) *Git

At returns a copy of g rooted at a different directory.

func (*Git) CurrentBranch

func (g *Git) CurrentBranch(ctx context.Context) (string, error)

CurrentBranch returns the checked-out branch, or "" when detached.

func (*Git) DeleteBranch

func (g *Git) DeleteBranch(ctx context.Context, branch string, force bool) error

DeleteBranch removes a local branch. With force it uses -D, which is only safe once GitHub has confirmed the PR merged (a squash merge leaves the branch looking unmerged to git).

func (*Git) Fetch

func (g *Git) Fetch(ctx context.Context, remote string, refs ...string) error

Fetch fetches refs from a remote. Callers treat failure as a warning.

func (*Git) FetchTags

func (g *Git) FetchTags(ctx context.Context, remote string) error

FetchTags fetches tags, which chart-version derivation depends on.

func (*Git) FindWorktree

func (g *Git) FindWorktree(ctx context.Context, path string) (Worktree, bool, error)

FindWorktree returns the worktree registered at path.

func (*Git) FindWorktreeForBranch

func (g *Git) FindWorktreeForBranch(ctx context.Context, branch string) (Worktree, bool, error)

FindWorktreeForBranch reports where a branch is already checked out. git refuses a second checkout of the same branch, so callers must ask first.

func (*Git) GitCommonDir

func (g *Git) GitCommonDir(ctx context.Context) (string, error)

GitCommonDir returns the shared .git directory for the repository, which is where info/exclude lives even when called from a linked worktree.

func (*Git) IsMergedInto

func (g *Git) IsMergedInto(ctx context.Context, branch, ref string) bool

IsMergedInto reports whether branch is reachable from ref. This is a useful cross-check before deleting a branch, but it misses squash merges, so it must never be the sole basis for deleting anything.

func (*Git) LatestTag

func (g *Git) LatestTag(ctx context.Context) (string, error)

LatestTag returns the most recently created tag, which is what the CI's chart-version computation starts from.

func (*Git) ListWorktrees

func (g *Git) ListWorktrees(ctx context.Context) ([]Worktree, error)

ListWorktrees returns every worktree git knows about for this repository.

func (*Git) LocalBranchExists

func (g *Git) LocalBranchExists(ctx context.Context, branch string) bool

LocalBranchExists reports whether refs/heads/{branch} exists.

func (*Git) PruneWorktrees

func (g *Git) PruneWorktrees(ctx context.Context) error

PruneWorktrees drops registrations whose directories no longer exist.

func (*Git) RemoteBranchExists

func (g *Git) RemoteBranchExists(ctx context.Context, remote, branch string) bool

RemoteBranchExists reports whether refs/remotes/{remote}/{branch} exists.

func (*Git) RemoveWorktree

func (g *Git) RemoveWorktree(ctx context.Context, path string, force bool) error

RemoveWorktree removes a worktree, optionally discarding local changes.

func (*Git) StatusOf

func (g *Git) StatusOf(ctx context.Context) (Status, error)

StatusOf inspects the worktree rooted at g.Dir.

func (*Git) Unpushed

func (g *Git) Unpushed(ctx context.Context, remote, branch, baseBranch string) ([]UnpushedCommit, error)

Unpushed lists commits on branch that the remote does not have. A branch that was never pushed reports every commit since the base branch.

type Repo

type Repo struct {
	// Root is the main worktree's root, never a linked worktree's.
	Root string
	// Key is "owner/name" from origin, or the absolute root path as a fallback.
	Key string
	// Owner and Name are set only when origin is a GitHub remote.
	Owner string
	Name  string
	// OriginURL is the raw remote URL, for diagnostics.
	OriginURL string
}

Repo identifies a git repository flow manages worktrees for.

func DiscoverRepo

func DiscoverRepo(ctx context.Context, r flowexec.Runner, dir, remote string) (Repo, error)

DiscoverRepo resolves the canonical repository containing dir.

It deliberately does not use `rev-parse --show-toplevel`: inside a linked worktree that returns the worktree path, not the repository. The common git dir's parent is the main worktree's root in both cases.

func (Repo) IsGitHub

func (r Repo) IsGitHub() bool

IsGitHub reports whether GitHub-dependent features can work for this repo.

type Status

type Status struct {
	// Dirty reports uncommitted changes.
	Dirty bool
	// ChangedFiles counts the porcelain entries.
	ChangedFiles int
	// HasUpstream reports whether the branch tracks a remote branch.
	HasUpstream bool
	Ahead       int
	Behind      int
}

Status summarizes a worktree's state relative to its upstream.

func (Status) Clean

func (s Status) Clean() bool

Clean reports a worktree with no local divergence at all.

type UnpushedCommit

type UnpushedCommit struct {
	SHA     string
	Subject string
}

UnpushedCommit is one commit present locally but not on the remote.

type Worktree

type Worktree struct {
	Path   string
	Branch string
	Head   string
	// Prunable reports a registered worktree whose directory is gone.
	Prunable bool
	Detached bool
	Bare     bool
}

Worktree is one entry from `git worktree list --porcelain`.

Jump to

Keyboard shortcuts

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