Skip to content

Pull

pull

Pull hook action.

Pulls a remote branch (default origin main) into the local repository. Used after worktree merge to keep the main branch up to date.

PullHook dataclass

Pull origin main into the local repository.

Reads optional branch and remote from params. Skips gracefully when the working directory is not a git repository.

Source code in packages/axm-git/src/axm_git/hooks/pull.py
@dataclass
class PullHook:
    """Pull ``origin main`` into the local repository.

    Reads optional ``branch`` and ``remote`` from *params*.
    Skips gracefully when the working directory is not a git repository.
    """

    def execute(self, context: dict[str, Any], **params: Any) -> HookResult:
        """Execute the hook action.

        Args:
            context: Session context dictionary.
            **params: Optional ``enabled`` (default ``True``),
                ``branch`` (default ``"main"``), ``remote`` (default ``"origin"``).

        Returns:
            HookResult with ``pulled`` and ``branch`` in metadata.
        """
        if not params.get("enabled", True):
            return HookResult.ok(skipped=True, reason="git disabled")

        working_dir = _resolve_working_dir(params, context)

        if not (working_dir / ".git").exists():
            return HookResult.ok(skipped=True, reason="not a git repo")

        remote = params.get("remote", "origin")
        branch = params.get("branch", "main")

        result = run_git(["pull", remote, branch], working_dir)
        if result.returncode != 0:
            return HookResult.fail(f"git pull failed: {result.stderr.strip()}")

        return HookResult.ok(pulled=True, branch=branch)
execute(context, **params)

Execute the hook action.

Parameters:

Name Type Description Default
context dict[str, Any]

Session context dictionary.

required
**params Any

Optional enabled (default True), branch (default "main"), remote (default "origin").

{}

Returns:

Type Description
HookResult

HookResult with pulled and branch in metadata.

Source code in packages/axm-git/src/axm_git/hooks/pull.py
def execute(self, context: dict[str, Any], **params: Any) -> HookResult:
    """Execute the hook action.

    Args:
        context: Session context dictionary.
        **params: Optional ``enabled`` (default ``True``),
            ``branch`` (default ``"main"``), ``remote`` (default ``"origin"``).

    Returns:
        HookResult with ``pulled`` and ``branch`` in metadata.
    """
    if not params.get("enabled", True):
        return HookResult.ok(skipped=True, reason="git disabled")

    working_dir = _resolve_working_dir(params, context)

    if not (working_dir / ".git").exists():
        return HookResult.ok(skipped=True, reason="not a git repo")

    remote = params.get("remote", "origin")
    branch = params.get("branch", "main")

    result = run_git(["pull", remote, branch], working_dir)
    if result.returncode != 0:
        return HookResult.fail(f"git pull failed: {result.stderr.strip()}")

    return HookResult.ok(pulled=True, branch=branch)