git

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 7 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     = vcs.ErrWorktreeNotFound
	ErrMultipleMatches      = vcs.ErrMultipleMatches
	ErrMainWorktree         = vcs.ErrMainWorktree
	ErrWorktreeIsCurrentDir = vcs.ErrWorktreeIsCurrentDir
	ErrBranchAlreadyInUse   = vcs.ErrBranchAlreadyInUse
	ErrPathAlreadyExists    = vcs.ErrPathAlreadyExists
	ErrWorktreeHasChanges   = vcs.ErrWorktreeHasChanges
)

Sentinel errors for worktree operations. These alias the shared vcs errors so that errors.Is works against either package's name — the jj backend wraps the same values, letting internal/cli render one set of messages for both.

View Source
var WorktreePath = vcs.WorktreePath

WorktreePath computes the sibling worktree directory path. Aliased from vcs so git and jj lay out their checkouts identically.

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.

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 = vcs.Worktree

Worktree represents a single git worktree entry. It is an alias of the shared vcs model so git and jj listings are the same type end to end.

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) Cleanable added in v0.6.0

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

Cleanable returns worktrees whose branch has been merged into the main worktree's branch, plus worktrees git reports as prunable.

func (*WorktreeManager) CurrentRef added in v0.6.0

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

CurrentRef returns the branch checked out at dir.

func (*WorktreeManager) FetchRefspec added in v0.6.0

func (wm *WorktreeManager) FetchRefspec(dir, remote, refspec string) error

FetchRefspec fetches a "src:dst" refspec from a remote.

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) Kind added in v0.6.0

func (wm *WorktreeManager) Kind() vcs.Kind

Kind reports that this manager drives git. Part of the vcs.Manager interface.

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 without deleting its branch. cwd is the caller's current working directory; removal is blocked if cwd falls inside the target worktree.

func (*WorktreeManager) StateDir added in v0.6.0

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

StateDir returns the shared .git/wtf directory used for wtf's repo-local state. It resolves via --git-common-dir so every worktree of a repo agrees on one location.

Jump to

Keyboard shortcuts

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