parseWorktrees parses the output of `git worktree list --porcelain` into a slice of Worktree. Each record begins with a "worktree " line followed by attribute lines.
(output []byte)
| 297 | // slice of Worktree. Each record begins with a "worktree <path>" line followed |
| 298 | // by attribute lines. |
| 299 | func parseWorktrees(output []byte) []Worktree { |
| 300 | var worktrees []Worktree |
| 301 | output = bytes.ReplaceAll(output, []byte("\r\n"), []byte("\n")) |
| 302 | for record := range strings.SplitSeq(string(output), "\n\n") { |
| 303 | var worktree Worktree |
| 304 | for line := range strings.SplitSeq(record, "\n") { |
| 305 | key, value, _ := strings.Cut(line, " ") |
| 306 | switch key { |
| 307 | case "worktree": |
| 308 | worktree.Path = value |
| 309 | case "branch": |
| 310 | worktree.Ref = value |
| 311 | case "prunable": |
| 312 | worktree.Prunable = true |
| 313 | } |
| 314 | } |
| 315 | if worktree.Path != "" { |
| 316 | worktrees = append(worktrees, worktree) |
| 317 | } |
| 318 | } |
| 319 | return worktrees |
| 320 | } |
| 321 | |
| 322 | func (c *Client) Config(ctx context.Context, name string) (string, error) { |
| 323 | args := []string{"config", name} |
no outgoing calls