Documentation
¶
Overview ¶
Package resolve provides target resolution for worktree commands.
Many wt commands operate on a specific worktree identified by its numeric ID. This package handles looking up worktrees from the cache and validating they still exist on disk.
ID-Based Resolution ¶
Use ByID to resolve a worktree target:
target, err := resolve.ByID(5, worktreeDir)
if err != nil {
// ID not found, worktree removed, or path doesn't exist
}
// target.Path, target.Branch, target.MainRepo available
Error Cases ¶
ByID returns descriptive errors for:
- ID not found in cache
- Worktree was marked as removed
- Path no longer exists on disk
- Cannot determine main repo path
Usage Pattern ¶
Commands that use ID resolution follow this pattern:
- Required ID: wt exec -n 5, wt cd -n 3
- Optional ID: wt note (defaults to current worktree), wt pr create
The -i/--id flag is used consistently across commands for worktree targeting. Commands may also support -r/--repository and -l/--label for repo-based targeting, but those are handled separately in the command implementations.
Index ¶
- type Target
- func ByID(id int, worktreeDir string) (*Target, error)
- func ByIDOrRepoOrPath(ctx context.Context, id int, repository, worktreeDir, repoDir, workDir string) (*Target, error)
- func ByRepoName(ctx context.Context, repoName, repoDir string) (*Target, error)
- func FromCurrentWorktree(ctx context.Context) (*Target, error)
- func FromCurrentWorktreeOrRepo(ctx context.Context) (*Target, error)
- func FromWorktreeOrRepoPath(ctx context.Context, path string) (*Target, error)
- func FromWorktreePath(ctx context.Context, path string) (*Target, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Target ¶
Target represents a resolved worktree target
func ByID ¶
ByID resolves a worktree target by its numeric ID only. Returns error if ID not found, worktree was removed, or path no longer exists.
func ByIDOrRepoOrPath ¶ added in v0.8.0
func ByIDOrRepoOrPath(ctx context.Context, id int, repository, worktreeDir, repoDir, workDir string) (*Target, error)
ByIDOrRepoOrPath resolves target with 3 modes: 1. id != 0: by worktree ID (uses worktreeDir) 2. repository != "": by repository name (uses repoDir, falls back to worktreeDir) 3. both empty: from current path (worktree or main repo)
func ByRepoName ¶ added in v0.7.0
ByRepoName resolves a target by repository name. Returns target with current branch of that repo.
func FromCurrentWorktree ¶ added in v0.7.0
FromCurrentWorktree resolves target from the current working directory. Returns error if not inside a git worktree.
func FromCurrentWorktreeOrRepo ¶ added in v0.7.0
FromCurrentWorktreeOrRepo resolves target from the current working directory. Works in both worktrees and main repos.
func FromWorktreeOrRepoPath ¶ added in v0.8.0
FromWorktreeOrRepoPath resolves target from the given path. Works in both worktrees and main repos.