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 ¶
- func ChangeCount(dir string) (int, error)
- func CommitInfos(dir string, shas []string) (map[string]CommitInfo, error)
- func DefaultBranch(dir string) string
- func HooksDir(dir string) (string, error)
- func IsAncestor(dir, commit, ref string) bool
- func IsDirty(dir string) (bool, error)
- func LocalBranchExists(dir, branch string) bool
- func RemoteBranchExists(dir, branch string) bool
- func Run(dir string, args ...string) (string, error)
- func Toplevel(dir string) (string, error)
- type CommitInfo
- type Worktree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ChangeCount ¶
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 ¶
DefaultBranch returns the repository's default branch: origin's HEAD when set, else main or master when one exists locally, else "main".
func HooksDir ¶
HooksDir returns the absolute path of the effective hooks directory for the worktree at dir, honoring core.hooksPath.
func IsAncestor ¶
IsAncestor reports whether commit is reachable from ref — i.e. merged.
func LocalBranchExists ¶
LocalBranchExists reports whether refs/heads/<branch> exists.
func RemoteBranchExists ¶
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.
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 ¶
ListWorktrees returns the worktrees of the repository containing dir. The first entry is always the main worktree.
func ParseWorktrees ¶
ParseWorktrees parses `git worktree list --porcelain` output: entries are separated by blank lines, each starting with a "worktree <path>" line.