DetectOrphanedWorktrees scans .chief/worktrees/ and returns a map of PRD name -> absolute worktree path for worktrees that exist on disk. The caller is responsible for determining which are orphaned (i.e., have no corresponding registered/running PRD).
(baseDir string)
| 199 | // for worktrees that exist on disk. The caller is responsible for determining which are orphaned |
| 200 | // (i.e., have no corresponding registered/running PRD). |
| 201 | func DetectOrphanedWorktrees(baseDir string) map[string]string { |
| 202 | worktreesDir := filepath.Join(baseDir, ".chief", "worktrees") |
| 203 | entries, err := os.ReadDir(worktreesDir) |
| 204 | if err != nil { |
| 205 | return nil |
| 206 | } |
| 207 | |
| 208 | result := make(map[string]string) |
| 209 | for _, entry := range entries { |
| 210 | if !entry.IsDir() { |
| 211 | continue |
| 212 | } |
| 213 | absPath := filepath.Join(worktreesDir, entry.Name()) |
| 214 | result[entry.Name()] = absPath |
| 215 | } |
| 216 | return result |
| 217 | } |
| 218 | |
| 219 | // MergeBranch merges a branch into the current branch, returning conflicting file list on failure. |
| 220 | func MergeBranch(repoDir, branch string) ([]string, error) { |