MCPcopy Create free account
hub / github.com/bearlyai/OpenADE / parseWorktreeList

Function parseWorktreeList

projects/electron/src/modules/code/git.ts:459–502  ·  view source on GitHub ↗

* Parse git worktree list --porcelain output

(output: string)

Source from the content-addressed store, hash-verified

457 * Parse git worktree list --porcelain output
458 */
459function parseWorktreeList(output: string): WorkTreeInfo[] {
460 const worktrees: WorkTreeInfo[] = []
461 const lines = output.split("\n")
462 let currentWorktree: Partial<WorkTreeInfo> = {}
463
464 for (const line of lines) {
465 if (line.startsWith("worktree ")) {
466 const worktreePath = line.substring(9).trim()
467 currentWorktree.path = worktreePath
468 // Extract ID from path
469 const baseDir = getWorktreeBaseDir()
470 if (worktreePath.startsWith(baseDir)) {
471 currentWorktree.id = path.basename(worktreePath)
472 }
473 } else if (line.startsWith("HEAD ")) {
474 currentWorktree.head = line.substring(5).trim()
475 } else if (line.startsWith("branch ")) {
476 currentWorktree.branch = line.substring(7).trim()
477 } else if (line === "" && currentWorktree.path) {
478 // Empty line marks end of worktree entry
479 if (currentWorktree.id && currentWorktree.path && currentWorktree.head) {
480 worktrees.push({
481 id: currentWorktree.id,
482 path: currentWorktree.path,
483 branch: currentWorktree.branch || "",
484 head: currentWorktree.head,
485 })
486 }
487 currentWorktree = {}
488 }
489 }
490
491 // Handle last entry if no trailing newline
492 if (currentWorktree.id && currentWorktree.path && currentWorktree.head) {
493 worktrees.push({
494 id: currentWorktree.id,
495 path: currentWorktree.path,
496 branch: currentWorktree.branch || "",
497 head: currentWorktree.head,
498 })
499 }
500
501 return worktrees
502}
503
504// ============================================================================
505// IPC Handlers

Callers 3

handleWorkTreeDiffPatchFunction · 0.85
handleListWorkTreesFunction · 0.85

Calls 2

getWorktreeBaseDirFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected