MCPcopy Create free account
hub / github.com/Graphify-Labs/graphify / fetch_worktrees

Function fetch_worktrees

graphify/prs.py:405–432  ·  view source on GitHub ↗

Returns {branch: worktree_path}. ``cwd`` selects the repository when the process working directory is not the graph's repo (MCP servers started outside the project, #5535).

(cwd: str | Path | None = None)

Source from the content-addressed store, hash-verified

403# ── Worktree mapping ──────────────────────────────────────────────────────────
404
405def fetch_worktrees(cwd: str | Path | None = None) -> dict[str, str]:
406 """Returns {branch: worktree_path}.
407
408 ``cwd`` selects the repository when the process working directory is not
409 the graph's repo (MCP servers started outside the project, #5535).
410 """
411 try:
412 result = subprocess.run(
413 ["git", "worktree", "list", "--porcelain"],
414 stdin=subprocess.DEVNULL,
415 capture_output=True, text=True, encoding="utf-8", errors="replace", timeout=10,
416 cwd=str(cwd) if cwd is not None else None,
417 )
418 if result.returncode != 0:
419 return {}
420 except (subprocess.TimeoutExpired, FileNotFoundError):
421 return {}
422
423 mapping: dict[str, str] = {}
424 current_path = None
425 for line in result.stdout.splitlines():
426 if not line:
427 current_path = None # blank line = record separator; reset to avoid leaking across detached HEADs
428 elif line.startswith("worktree "):
429 current_path = line[9:]
430 elif line.startswith("branch refs/heads/") and current_path:
431 mapping[line[18:]] = current_path
432 return mapping
433
434
435# ── Graph impact analysis ─────────────────────────────────────────────────────

Calls 1

runMethod · 0.65