ListWorktrees enumerates all worktrees registered with the repository containing `path`. The primary worktree is always the first entry.
(path string)
| 57 | // ListWorktrees enumerates all worktrees registered with the repository |
| 58 | // containing `path`. The primary worktree is always the first entry. |
| 59 | func ListWorktrees(path string) ([]Worktree, error) { |
| 60 | stdout, stderr, err := runGitCommand(path, "worktree", "list", "--porcelain") |
| 61 | if err != nil { |
| 62 | return nil, gitCommandError(err, stderr) |
| 63 | } |
| 64 | return parseWorktreePorcelain(string(stdout)), nil |
| 65 | } |
| 66 | |
| 67 | // parseWorktreePorcelain parses the output of `git worktree list --porcelain`. |
| 68 | // Stanzas are separated by blank lines. Each stanza begins with `worktree <path>`, |