Something went wrong. Try again.
Integrated repository, worktree, git stacker, and project manager
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556"""`pm cd` — resolve and print the path to a project (or worktree).
`cd` is a shell builtin, so the python program can only print theresolved path — the actual directory change happens in the`integrations/pm-cd.zsh` shell wrapper, which captures stdout and runs`builtin cd`. `--print` opts out of that wrapper for scripting."""
from typing import Annotated
from cyclopts import Parameter
from project_manager import configfrom project_manager.errors import ProjectErrorfrom project_manager.project import discovery
from ._shared import root
@root.commanddef cd( project: str, wt: str | None = None, *, print_: Annotated[ bool, Parameter( name="--print", negative="", help="print the path instead of cd'ing (opts out of the shell wrapper)", ), ] = False,) -> int: """Change directory to a project, or one of its worktrees.
With `integrations/pm-cd.zsh` sourced, `pm cd <project>` cd's into the project. Pass `--print` to print the path instead — useful in scripts (`cd "$(pm cd --print myproj)"`). """ del print_ # consumed by the shell wrapper; python always prints. paths = config.load() discovery.require_project_db(paths, project) if wt is None: print(paths.project(project)) return 0 rows = discovery.read_wts(paths, project) if wt not in {w for w, _, _ in rows}: raise ProjectError(f"project '{project}' has no worktree '{wt}'") forward = paths.forward(project, wt) if not forward.is_symlink(): raise ProjectError( f"worktree '{wt}' is detached; run `pm project wt attach -p {project} --wt {wt}`", ) print(forward) return 0