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

Function parseWorktrees

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

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

Callers 2

TestParseWorktreesFunction · 0.85
WorktreesMethod · 0.85

Calls

no outgoing calls

Tested by 1

TestParseWorktreesFunction · 0.68