Documentation
¶
Index ¶
- Variables
- func AgeDays(path string) (int, error)
- func AgeHours(path string) (int, error)
- func CleanAllStaleLocks(cfg *config.Config)
- func CleanStaleLocks(cfg *config.Config, repo string)
- func CleanupFailedAdd(originPath, worktreePath, branch string)
- func CreateFromMain(originPath, worktreePath, worktreeName, branch string) error
- func CreateFromPR(originPath, worktreePath, worktreeName string, prNumber int) error
- func LastActivity(path string) (time.Time, error)
- func ParseBranchFromName(name string) string
- func ParseRepoFromName(name string) string
- func RemoveStaleLock(lockFile, name string)
- type Stats
- type Type
- type Worktree
Constants ¶
This section is empty.
Variables ¶
var GitMu sync.Mutex
GitMu serializes git worktree operations to prevent concurrent index.lock conflicts.
Functions ¶
func CleanAllStaleLocks ¶
CleanAllStaleLocks cleans stale locks across all known repos.
func CleanStaleLocks ¶
CleanStaleLocks removes stale index.lock files from worktrees of the given repo. A lock is considered stale if the PID inside it is no longer running.
func CleanupFailedAdd ¶ added in v0.7.0
func CleanupFailedAdd(originPath, worktreePath, branch string)
CleanupFailedAdd cleans up after a failed "git worktree add" that may have created the branch and/or a partial worktree directory but failed to complete (e.g., "Could not write new index file"). It removes the partial worktree directory, prunes git's worktree metadata, and deletes the orphaned branch.
originPath is the main repo directory, worktreePath is the target worktree directory, and branch is the git branch that was being created.
func CreateFromMain ¶ added in v0.11.0
CreateFromMain fetches origin/main and creates a new worktree checked out to a new branch cut from it. Used for feature work (branch didn't exist before), as opposed to PR review worktrees which check out an existing remote branch/ref instead.
Uses --no-checkout + a separate checkout to avoid "Could not write new index file" on large repos (13K+ files) — the two-step approach handles the index write reliably. Serializes on GitMu to prevent concurrent index.lock conflicts across worktree operations on the same origin repo.
func CreateFromPR ¶ added in v0.11.0
CreateFromPR fetches the PR's remote branch (pull/N/head) into a local pr-N branch and creates a worktree checked out to it. Used for PR review worktrees, which check out an existing remote ref, as opposed to CreateFromMain which cuts a brand new branch for feature work.
If worktreePath already exists by the time the lock is acquired (e.g. a concurrent caller created it first), this is a no-op — callers that need a fast pre-lock existence check too (to skip the wait entirely in the common case) can still do their own os.Stat before calling.
Uses --no-checkout + a separate checkout to avoid "Could not write new index file" on large repos (13K+ files) — the two-step approach handles the index write reliably. Serializes on GitMu to prevent concurrent index.lock conflicts across worktree operations on the same origin repo.
func LastActivity ¶
LastActivity returns the date of the last commit in the worktree.
func ParseBranchFromName ¶
ParseBranchFromName extracts the branch suffix from a worktree directory name. e.g., "mono-feature-branch" -> "feature-branch"
func ParseRepoFromName ¶
ParseRepoFromName extracts the repo short name from a worktree directory name. e.g., "mono-pr-1234" -> "mono"
func RemoveStaleLock ¶ added in v0.7.0
func RemoveStaleLock(lockFile, name string)
RemoveStaleLock removes an index.lock file only if the holding process is no longer running. Safe to call if the file does not exist.
Types ¶
type Stats ¶
type Stats struct {
Total int `json:"total"`
PRReviews int `json:"pr_reviews"`
Features int `json:"features"`
ByRepo map[string]int `json:"by_repo"`
}
Stats holds worktree statistics.
type Worktree ¶
type Worktree struct {
Path string `json:"path"`
Name string `json:"name"`
Branch string `json:"branch"`
Type Type `json:"type"`
PRNumber int `json:"pr_number,omitempty"`
Repo string `json:"repo"`
}
Worktree represents a discovered git worktree.