git

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBranchAlreadyExists = errors.New("branch already exists")
	ErrInvalidBranchName   = errors.New("invalid branch name")
)

Sentinel errors for branch operations.

View Source
var (
	ErrWorktreeNotFound     = errors.New("no matching worktree found")
	ErrMultipleMatches      = errors.New("multiple worktrees match query")
	ErrMainWorktree         = errors.New("cannot remove main worktree")
	ErrWorktreeIsCurrentDir = errors.New("cannot remove worktree for the currently checked out branch")
	ErrBranchAlreadyInUse   = errors.New("branch is already checked out")
	ErrPathAlreadyExists    = errors.New("worktree path already exists")
	ErrWorktreeHasChanges   = errors.New("worktree has uncommitted changes")
)

Sentinel errors for worktree operations.

Functions

func CommitURL

func CommitURL(remoteURL, commitHash string) string

CommitURL builds a web URL for the given commit hash from a git remote URL. Supports GitHub and GitLab, both SSH and HTTPS formats. Returns empty string if the remote URL format is not recognized.

func WorktreePath

func WorktreePath(mainPath, branch string) string

WorktreePath computes the sibling worktree directory path. /code/myrepo + feature/auth → /code/myrepo--feature-auth

Types

type BranchManager

type BranchManager struct {
	// contains filtered or unexported fields
}

BranchManager handles branch-related operations.

func NewBranchManager

func NewBranchManager(executor Executor) *BranchManager

NewBranchManager creates a new BranchManager.

func (*BranchManager) CurrentBranch

func (bm *BranchManager) CurrentBranch(dir string) (string, error)

CurrentBranch returns the current branch name.

func (*BranchManager) Exists

func (bm *BranchManager) Exists(dir, branch string) (bool, error)

Exists checks if a branch exists in the repo.

func (*BranchManager) MergedBranches

func (bm *BranchManager) MergedBranches(dir, base string) ([]string, error)

MergedBranches returns branches whose unique commits have been merged into the given base branch. Branches that sit at the exact same commit as base are excluded — they never diverged, so they are not "merged".

func (*BranchManager) RemoteBranches added in v0.4.0

func (bm *BranchManager) RemoteBranches(dir string) ([]string, error)

RemoteBranches returns remote branch names with the remote prefix stripped. For example, "origin/feature-x" becomes "feature-x". HEAD pointers (e.g., "origin/HEAD -> origin/main") are excluded.

func (*BranchManager) ValidateBranchName

func (bm *BranchManager) ValidateBranchName(name string) error

ValidateBranchName checks if a branch name is valid using git check-ref-format.

type Executor

type Executor interface {
	// Run executes a git command in the given directory and returns stdout.
	Run(dir string, args ...string) (string, error)
}

Executor abstracts git CLI calls for testability.

type RealExecutor

type RealExecutor struct{}

RealExecutor shells out to the git CLI.

func (*RealExecutor) Run

func (r *RealExecutor) Run(dir string, args ...string) (string, error)

Run executes a git command in the given directory and returns stdout.

type Worktree

type Worktree struct {
	Path       string `json:"path"`
	Branch     string `json:"branch"`
	Head       string `json:"head"`
	IsMain     bool   `json:"is_main"`
	IsBare     bool   `json:"is_bare"`
	IsDetached bool   `json:"is_detached"`
	Prunable   bool   `json:"prunable"`
}

Worktree represents a single git worktree entry.

type WorktreeManager

type WorktreeManager struct {
	// contains filtered or unexported fields
}

WorktreeManager handles worktree operations.

func NewWorktreeManager

func NewWorktreeManager(executor Executor) *WorktreeManager

NewWorktreeManager creates a new WorktreeManager with the given executor.

func (*WorktreeManager) Add

func (wm *WorktreeManager) Add(dir, branch, base string) (string, error)

Add creates a new worktree for the given branch.

func (*WorktreeManager) Find

func (wm *WorktreeManager) Find(dir, query string) (Worktree, error)

Find searches worktrees by substring match on branch name. Returns the matching worktree, or an error if zero or multiple matches.

func (*WorktreeManager) List

func (wm *WorktreeManager) List(dir string) ([]Worktree, error)

List returns all worktrees for the repo at dir.

func (*WorktreeManager) MainWorktree

func (wm *WorktreeManager) MainWorktree(dir string) (Worktree, error)

MainWorktree returns the main (first) worktree.

func (*WorktreeManager) RemoteURL

func (wm *WorktreeManager) RemoteURL(dir string) (string, error)

RemoteURL returns the URL of the "origin" remote for the repo at dir.

func (*WorktreeManager) Remove

func (wm *WorktreeManager) Remove(dir, branch, cwd string, force bool) error

Remove removes a worktree and optionally deletes the branch. cwd is the caller's current working directory; removal is blocked if cwd falls inside the target worktree.

Jump to

Keyboard shortcuts

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