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 GitDirInfo
- 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 GitDirInfo ¶ added in v0.3.0
type GitDirInfo struct {
// MainGitDir is the absolute path to the main .git directory (shared objects, refs).
MainGitDir string
// WorktreeGitDir is the absolute path to the worktree-specific git dir
// (e.g., main-repo/.git/worktrees/<branch>). Always a subdirectory of MainGitDir.
WorktreeGitDir string
}
GitDirInfo holds the resolved git directory paths for a worktree workspace.
func ResolveGitDir ¶ added in v0.3.0
func ResolveGitDir(workspace string) (*GitDirInfo, error)
ResolveGitDir detects whether workspace is a git worktree and returns the paths needed to make git operations work inside a container. Returns (nil, nil) if workspace is not a worktree (regular repo or no .git).
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.