resolve

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: MIT Imports: 5 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Target

type Target struct {
	ID       int
	Branch   string
	MainRepo string
	Path     string
}

Target represents a resolved worktree target

func ByID

func ByID(id int, worktreeDir string) (*Target, error)

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

func ByRepoName(ctx context.Context, repoName, repoDir string) (*Target, error)

ByRepoName resolves a target by repository name. Returns target with current branch of that repo.

func FromCurrentWorktree added in v0.7.0

func FromCurrentWorktree(ctx context.Context) (*Target, error)

FromCurrentWorktree resolves target from the current working directory. Returns error if not inside a git worktree.

func FromCurrentWorktreeOrRepo added in v0.7.0

func FromCurrentWorktreeOrRepo(ctx context.Context) (*Target, error)

FromCurrentWorktreeOrRepo resolves target from the current working directory. Works in both worktrees and main repos.

func FromWorktreeOrRepoPath added in v0.8.0

func FromWorktreeOrRepoPath(ctx context.Context, path string) (*Target, error)

FromWorktreeOrRepoPath resolves target from the given path. Works in both worktrees and main repos.

func FromWorktreePath added in v0.8.0

func FromWorktreePath(ctx context.Context, path string) (*Target, error)

FromWorktreePath resolves target from the given path. Returns error if the path is not inside a git worktree.

Jump to

Keyboard shortcuts

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