pub fn resolve_project(
explicit_path: Option<&Path>,
command_name: &str,
) -> Result<ResolvedProject, CliError>Expand description
Common project resolution logic used by every CLI command.
The resolver walks to the git common-dir parent BEFORE deriving the project name, so all worktrees of a single repository share one DB. The caller decides whether a missing DB is an error.
command_name is used in error messages to identify the calling command.
Resolution priority:
- Explicit argument that names an existing directory → resolve from it.
- Explicit argument that names a known project (DB exists in repos_dir) → recover scan-time root from DB metadata.
- No argument: derive from cwd. The DB is keyed by the cwd’s git-root basename so worktrees collapse to one DB.
- cwd is not in a git repo and has no DB → fall back to listing available projects (auto-select when exactly one exists).