Documentation
¶
Index ¶
- Variables
- func CommitURL(remoteURL, commitHash string) string
- func WorktreePath(mainPath, branch string) string
- type BranchManager
- func (bm *BranchManager) CurrentBranch(dir string) (string, error)
- func (bm *BranchManager) Exists(dir, branch string) (bool, error)
- func (bm *BranchManager) MergedBranches(dir, base string) ([]string, error)
- func (bm *BranchManager) RemoteBranches(dir string) ([]string, error)
- func (bm *BranchManager) ValidateBranchName(name string) error
- type Executor
- type RealExecutor
- type Worktree
- type WorktreeManager
- func (wm *WorktreeManager) Add(dir, branch, base string) (string, error)
- func (wm *WorktreeManager) Find(dir, query string) (Worktree, error)
- func (wm *WorktreeManager) List(dir string) ([]Worktree, error)
- func (wm *WorktreeManager) MainWorktree(dir string) (Worktree, error)
- func (wm *WorktreeManager) RemoteURL(dir string) (string, error)
- func (wm *WorktreeManager) Remove(dir, branch, cwd string, force bool) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrBranchAlreadyExists = errors.New("branch already exists") ErrInvalidBranchName = errors.New("invalid branch name") )
Sentinel errors for branch operations.
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 ¶
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 ¶
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 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.