Documentation
¶
Overview ¶
Package worktree orchestrates git worktree lifecycle operations.
Index ¶
- Variables
- func CreateSymlinks(mainRepo, wtPath string, links []string) error
- func Delete(ctx context.Context, r exec.Runner, opts DeleteOpts) error
- func DirName(name string) string
- func GenerateName() string
- func MainPath(wts []Worktree) string
- func Rename(ctx context.Context, r exec.Runner, opts RenameOpts) error
- type CreateOpts
- type DeleteOpts
- type RenameOpts
- type Worktree
Constants ¶
This section is empty.
Variables ¶
var ErrWorktreeExists = errors.New("worktree already exists")
ErrWorktreeExists is returned when a worktree directory already exists.
Functions ¶
func CreateSymlinks ¶
CreateSymlinks creates symlinks in the worktree pointing back to files/dirs in the main repo. Skips entries that don't exist in the main repo.
func Delete ¶
Delete removes a worktree and prunes stale references. If the worktree directory is already gone, it prunes the stale entry instead. Branch deletion is handled by the CLI layer (may require user prompt).
func DirName ¶ added in v1.0.3
DirName returns the directory name used for a worktree, replacing slashes with dashes so branch-style names like "fix/foo" become "fix-foo".
func GenerateName ¶
func GenerateName() string
GenerateName returns a random adjective-verbing-noun triple like "calm-spinning-oak".
func MainPath ¶ added in v1.0.4
MainPath returns the path of the main (first) worktree from a pre-fetched list. Git always lists the main worktree first.
func Rename ¶ added in v1.4.0
Rename renames the branch and moves the worktree directory. The move is skipped when NewPath is empty or already equal to OldPath, which renames the branch alone.
A failed move rolls the branch name back, so the worktree is left as it was found. The caller must not be inside the worktree being moved: git resolves the move against the process working directory.
The tmux session is not touched; that is handled by the CLI layer, as with Delete and branch deletion.
Types ¶
type CreateOpts ¶
type CreateOpts struct {
Name string
Base string
SkipSetup bool
SkipSymlinks bool
Progress io.Writer
}
CreateOpts holds options for creating a worktree.
type DeleteOpts ¶
DeleteOpts holds options for deleting a worktree.
type RenameOpts ¶ added in v1.4.0
type RenameOpts struct {
OldBranch string
NewBranch string
OldPath string
NewPath string
Progress io.Writer
}
RenameOpts holds options for renaming a worktree.
type Worktree ¶
Worktree represents a single git worktree entry.
func Create ¶
func Create(ctx context.Context, r exec.Runner, cfg *config.Config, opts CreateOpts) (*Worktree, error)
Create creates a new worktree with optional symlinks and setup command.
func FindByName ¶ added in v1.0.4
FindByName returns the worktree whose directory basename matches the given name. Returns nil if no match is found.
func FindByPath ¶ added in v1.1.0
FindByPath returns the worktree that contains the given absolute path. A path is "inside" a worktree if it equals or is a subdirectory of the worktree root. Returns nil if no match is found.