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