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
- func DirExists(path string) bool
- func DirIsEmpty(path string) bool
- func EnsureExcluded(commonDir, line string) (added bool, err error)
- func ParseGitHubRemote(raw string) (owner, name string, ok bool)
- func ResolvePath(p string) string
- func SamePath(a, b string) bool
- type Git
- func (g *Git) AddWorktreeExisting(ctx context.Context, path, branch string) error
- func (g *Git) AddWorktreeFromBase(ctx context.Context, path, branch, startPoint string) error
- func (g *Git) AddWorktreeTracking(ctx context.Context, path, branch, remote string) error
- func (g *Git) At(dir string) *Git
- func (g *Git) CurrentBranch(ctx context.Context) (string, error)
- func (g *Git) DeleteBranch(ctx context.Context, branch string, force bool) error
- func (g *Git) Fetch(ctx context.Context, remote string, refs ...string) error
- func (g *Git) FetchTags(ctx context.Context, remote string) error
- func (g *Git) FindWorktree(ctx context.Context, path string) (Worktree, bool, error)
- func (g *Git) FindWorktreeForBranch(ctx context.Context, branch string) (Worktree, bool, error)
- func (g *Git) GitCommonDir(ctx context.Context) (string, error)
- func (g *Git) IsMergedInto(ctx context.Context, branch, ref string) bool
- func (g *Git) LatestTag(ctx context.Context) (string, error)
- func (g *Git) ListWorktrees(ctx context.Context) ([]Worktree, error)
- func (g *Git) LocalBranchExists(ctx context.Context, branch string) bool
- func (g *Git) PruneWorktrees(ctx context.Context) error
- func (g *Git) RemoteBranchExists(ctx context.Context, remote, branch string) bool
- func (g *Git) RemoveWorktree(ctx context.Context, path string, force bool) error
- func (g *Git) StatusOf(ctx context.Context) (Status, error)
- func (g *Git) Unpushed(ctx context.Context, remote, branch, baseBranch string) ([]UnpushedCommit, error)
- type Repo
- type Status
- type UnpushedCommit
- type Worktree
Constants ¶
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 DirIsEmpty ¶
DirIsEmpty reports whether path is a directory with no entries.
func EnsureExcluded ¶
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 ¶
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 ¶
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.
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 (*Git) AddWorktreeExisting ¶
AddWorktreeExisting checks out an existing local branch into a new worktree.
func (*Git) AddWorktreeFromBase ¶
AddWorktreeFromBase creates a new branch off an arbitrary start point.
func (*Git) AddWorktreeTracking ¶
AddWorktreeTracking creates a branch tracking {remote}/{branch}.
func (*Git) CurrentBranch ¶
CurrentBranch returns the checked-out branch, or "" when detached.
func (*Git) DeleteBranch ¶
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) FindWorktree ¶
FindWorktree returns the worktree registered at path.
func (*Git) FindWorktreeForBranch ¶
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 ¶
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 ¶
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 ¶
LatestTag returns the most recently created tag, which is what the CI's chart-version computation starts from.
func (*Git) ListWorktrees ¶
ListWorktrees returns every worktree git knows about for this repository.
func (*Git) LocalBranchExists ¶
LocalBranchExists reports whether refs/heads/{branch} exists.
func (*Git) PruneWorktrees ¶
PruneWorktrees drops registrations whose directories no longer exist.
func (*Git) RemoteBranchExists ¶
RemoteBranchExists reports whether refs/remotes/{remote}/{branch} exists.
func (*Git) RemoveWorktree ¶
RemoveWorktree removes a worktree, optionally discarding local changes.
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 ¶
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.
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.
type UnpushedCommit ¶
UnpushedCommit is one commit present locally but not on the remote.