MCPcopy Create free account
hub / github.com/cli/cli / parseWorktrees

Function parseWorktrees

git/client.go:299–320  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

297// slice of Worktree. Each record begins with a "worktree <path>" line followed
298// by attribute lines.
299func 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
322func (c *Client) Config(ctx context.Context, name string) (string, error) {
323 args := []string{"config", name}

Callers 2

TestParseWorktreesFunction · 0.85
WorktreesMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestParseWorktreesFunction · 0.68