Documentation
¶
Overview ¶
Package worktree provides git worktree management for moat runs.
Index ¶
- func BasePath() string
- func Clean(repoRoot, wtPath string) error
- func FindRepoRoot(dir string) (string, error)
- func ParseRemoteURL(rawURL string) (string, error)
- func Path(repoID, branch string) string
- func ResolveRepoID(repoRoot string) (string, error)
- func ValidateBranch(branch string) error
- type Entry
- type Result
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasePath ¶
func BasePath() string
BasePath returns the root directory for worktrees. Checks MOAT_WORKTREE_BASE env var, defaults to ~/.moat/worktrees.
func Clean ¶
Clean removes a worktree directory and runs git worktree prune. The wtPath must be under BasePath() to prevent path traversal attacks.
func FindRepoRoot ¶
FindRepoRoot returns the root of the git repository containing dir.
func ParseRemoteURL ¶
ParseRemoteURL normalizes a git remote URL to host/owner/repo format. Handles both HTTPS and SSH URLs, strips .git suffix.
func ResolveRepoID ¶
ResolveRepoID returns a normalized repository identifier. Uses the origin remote URL if available, otherwise falls back to _local/<dirname>.
func ValidateBranch ¶
ValidateBranch checks that a branch name is safe to use in filesystem paths.
Types ¶
type Entry ¶
type Entry struct {
Branch string // branch name (directory name)
Path string // absolute path to worktree
}
Entry represents a managed worktree on disk.
func ListWorktrees ¶
ListWorktrees returns all managed worktree entries for a given repo ID. It walks the directory tree to find worktrees, supporting branch names with slashes (e.g., feature/dark-mode) which create nested directories. A worktree is identified by the presence of a .git file (not directory) in its root, which git creates for worktrees.
type Result ¶
type Result struct {
WorkspacePath string // absolute path to worktree directory
Branch string // git branch name
RunName string // auto-generated run name ({agent}-{branch} or {branch})
Reused bool // true if worktree already existed
RepoID string // normalized repo identifier
}
Result holds the outcome of a worktree resolution.