git

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package git wraps the git plumbing commands wt shells out to.

Index

Constants

View Source
const DetachedBranch = "(detached)"

DetachedBranch is the sentinel Worktree.Branch value for a worktree checked out at a detached HEAD (no branch).

Variables

This section is empty.

Functions

func BranchDelete

func BranchDelete(mainDir, branch string) error

BranchDelete runs `git branch -d <branch>` in mainDir.

func DefaultBranch

func DefaultBranch(mainDir string) (name string, err error)

DefaultBranch returns the short name of origin's default branch (e.g. "main"), resolved from the local origin/HEAD symref. Returns "" if the symref simply isn't set (the common, benign case). err is non-nil only for an unexpected failure (e.g. git missing, repo corruption) — distinct from "not set" so callers can tell the two apart.

func Fetch

func Fetch(mainDir string) error

Fetch runs `git fetch origin` in mainDir.

func IgnoredFiles added in v0.1.3

func IgnoredFiles(mainDir string) ([]string, error)

IgnoredFiles returns paths mainDir's gitignore rules ignore, relative to mainDir — from `git status --porcelain --ignored --untracked-files=all`. A directory that's entirely ignored is returned as one entry (its trailing slash stripped), not walked file by file.

func MainDir

func MainDir() (string, error)

MainDir resolves the main checkout root, even when the current directory is inside a linked worktree. It shells out to `git rev-parse --git-common-dir` and returns the parent of that dir.

func RefExists

func RefExists(mainDir, ref string) bool

RefExists reports whether ref resolves to a valid object in mainDir.

func WorktreeAdd

func WorktreeAdd(mainDir, dir, branch, baseRef string) error

WorktreeAdd runs `git worktree add <dir> -b <branch> <baseRef>` in mainDir.

func WorktreePrune

func WorktreePrune(mainDir string) error

WorktreePrune runs `git worktree prune` in mainDir.

func WorktreeRemove

func WorktreeRemove(mainDir, dir string) error

WorktreeRemove runs `git worktree remove <dir>` in mainDir.

Types

type Worktree

type Worktree struct {
	Path   string
	Branch string
}

Worktree is one entry from `git worktree list`: its checkout path and the branch checked out there (DetachedBranch if none).

func WorktreeList

func WorktreeList(mainDir string) ([]Worktree, error)

WorktreeList returns all worktrees registered against mainDir (the main checkout included), parsed from `git worktree list --porcelain`.

Jump to

Keyboard shortcuts

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