gitx

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package gitx shells out to the git binary. It deliberately avoids go-git: its worktree support is incomplete, while `git worktree list --porcelain` is a stable scripting interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ChangeCount

func ChangeCount(dir string) (int, error)

ChangeCount returns the number of pending files in the worktree at dir: staged, unstaged, and untracked.

func CommitInfos

func CommitInfos(dir string, shas []string) (map[string]CommitInfo, error)

CommitInfos returns display info for each sha, keyed by full sha.

func DefaultBranch

func DefaultBranch(dir string) string

DefaultBranch returns the repository's default branch: origin's HEAD when set, else main or master when one exists locally, else "main".

func HooksDir

func HooksDir(dir string) (string, error)

HooksDir returns the absolute path of the effective hooks directory for the worktree at dir, honoring core.hooksPath.

func IsAncestor

func IsAncestor(dir, commit, ref string) bool

IsAncestor reports whether commit is reachable from ref — i.e. merged.

func IsDirty

func IsDirty(dir string) (bool, error)

IsDirty reports whether the worktree at dir has modified or untracked files.

func LocalBranchExists

func LocalBranchExists(dir, branch string) bool

LocalBranchExists reports whether refs/heads/<branch> exists.

func RemoteBranchExists

func RemoteBranchExists(dir, branch string) bool

RemoteBranchExists reports whether origin has branch, fetching once if the remote-tracking ref is not yet known locally. A failed fetch (e.g. no origin remote) just means the branch is treated as not existing remotely.

func Run

func Run(dir string, args ...string) (string, error)

Run executes git with args in dir and returns stdout with the trailing newline removed. On failure the error carries git's stderr.

func Toplevel

func Toplevel(dir string) (string, error)

Toplevel returns the root of the worktree containing dir.

Types

type CommitInfo

type CommitInfo struct {
	ShortHash string
	When      string // relative, e.g. "3 days ago"
	Subject   string
}

CommitInfo describes a commit for display.

type Worktree

type Worktree struct {
	Path           string `json:"path"`
	Head           string `json:"head,omitempty"`
	Branch         string `json:"branch,omitempty"`
	Bare           bool   `json:"bare,omitempty"`
	Detached       bool   `json:"detached,omitempty"`
	Locked         bool   `json:"locked,omitempty"`
	LockedReason   string `json:"locked_reason,omitempty"`
	Prunable       bool   `json:"prunable,omitempty"`
	PrunableReason string `json:"prunable_reason,omitempty"`
}

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

func ListWorktrees

func ListWorktrees(dir string) ([]Worktree, error)

ListWorktrees returns the worktrees of the repository containing dir. The first entry is always the main worktree.

func ParseWorktrees

func ParseWorktrees(out string) []Worktree

ParseWorktrees parses `git worktree list --porcelain` output: entries are separated by blank lines, each starting with a "worktree <path>" line.

Jump to

Keyboard shortcuts

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