git

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsGitRepo

func IsGitRepo(cwd string) bool

IsGitRepo reports whether cwd is inside a git repository. It returns false (without an error) when git is unavailable or the directory is not tracked by git.

func IsWorktreeRoot

func IsWorktreeRoot(dir string) bool

IsWorktreeRoot reports whether dir is the root of a git worktree

func RepoRoot

func RepoRoot(cwd string) (string, error)

RepoRoot returns the toplevel directory of the git repository that contains cwd, or an error if cwd is not inside a git repository.

Types

type Worktree

type Worktree struct {
	// Path is the absolute filesystem path to the worktree.
	Path string
	// Branch is the checked-out branch name (e.g. "refs/heads/main").
	// Empty string for detached HEAD worktrees.
	Branch string
	// HEAD is the commit SHA the worktree is currently on.
	HEAD string
	// IsBare is true when the worktree is a bare clone.
	IsBare bool
}

Worktree represents a single git worktree entry.

func CurrentWorktree

func CurrentWorktree(cwd string) (Worktree, error)

CurrentWorktree returns the Worktree entry that corresponds to cwd, or an error if it cannot be determined.

func ListWorktrees

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

ListWorktrees returns all worktrees for the repository that contains cwd. The list is parsed from the output of `git worktree list --porcelain`.

func (Worktree) ShortBranch

func (w Worktree) ShortBranch() string

ShortBranch returns the branch name with the "refs/heads/" prefix stripped, or "(detached)" when the worktree is in detached HEAD state.

Jump to

Keyboard shortcuts

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