28 lines
899 B
Python
28 lines
899 B
Python
from loop_claude.effects import Effects
|
|
from loop_claude.outcome import Stop
|
|
|
|
|
|
def checkout_root(cwd, effects: Effects) -> str | Stop:
|
|
try:
|
|
found = effects.run(["git", "rev-parse", "--show-toplevel"], capture_output=True, cwd=cwd, text=True)
|
|
except OSError as failure:
|
|
return Stop(1, f"could not start git: {failure.strerror}")
|
|
if found.returncode != 0:
|
|
return Stop(1, found.stderr.strip())
|
|
return found.stdout.strip()
|
|
|
|
|
|
def checkouts(root, effects: Effects) -> list[str]:
|
|
found = [root]
|
|
try:
|
|
listing = effects.run(["git", "worktree", "list", "--porcelain"], capture_output=True, cwd=root, text=True)
|
|
except OSError:
|
|
return found
|
|
if listing.returncode == 0:
|
|
found += [line.split(" ", 1)[1] for line in listing.stdout.splitlines() if line.startswith("worktree ")]
|
|
return sorted(set(found))
|
|
|
|
|
|
def project_name(root, code) -> str:
|
|
return root.removeprefix(f"{code}/").lstrip("/")
|