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

Function parseWorktrees

git/client.go:305–326  ·  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

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

Callers 2

TestParseWorktreesFunction · 0.85
WorktreesMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestParseWorktreesFunction · 0.68