Skip to content

resolve

_resolve

Working directory resolution helpers for git hooks.

resolve_working_dir(params, context, *, param_key='working_dir')

Resolve the working directory from params and context.

Handles the case where worktree_path in context is a dict (as stored by WorktreeAddHook via inject_result).

Parameters:

Name Type Description Default
params dict[str, object]

Hook keyword parameters.

required
context dict[str, object]

Session context dictionary.

required
param_key str

Parameter key to check first (default "working_dir").

'working_dir'

Returns:

Type Description
Path

Resolved working directory as a Path.

Source code in packages/axm-git/src/axm_git/hooks/_resolve.py
Python
def resolve_working_dir(
    params: dict[str, object],
    context: dict[str, object],
    *,
    param_key: str = "working_dir",
) -> Path:
    """Resolve the working directory from params and context.

    Handles the case where ``worktree_path`` in context is a dict
    (as stored by ``WorktreeAddHook`` via ``inject_result``).

    Args:
        params: Hook keyword parameters.
        context: Session context dictionary.
        param_key: Parameter key to check first (default ``"working_dir"``).

    Returns:
        Resolved working directory as a Path.
    """
    raw: object = params.get(
        param_key,
        context.get("worktree_path", context.get("working_dir", ".")),
    )
    if isinstance(raw, dict):
        nested = cast("dict[str, object]", raw)
        raw = nested.get("worktree_path", nested.get("path", "."))
    return Path(cast("str | Path", raw))