Skip to content

Merge

merge

GitMergeTool — squash-merge a branch into a target branch.

GitMergeTool

Bases: AXMTool

Squash-merge a branch into a target branch and commit.

Checks out target_branch, runs git merge --squash <branch>, then commits the squashed changes (honouring the identity-profile system). Registered as git_merge via axm.tools entry point.

Source code in packages/axm-git/src/axm_git/tools/merge.py
Python
class GitMergeTool(AXMTool):
    """Squash-merge a branch into a target branch and commit.

    Checks out *target_branch*, runs ``git merge --squash <branch>``, then
    commits the squashed changes (honouring the identity-profile system).
    Registered as ``git_merge`` via axm.tools entry point.
    """

    domain = "git"
    tags = frozenset({"merge", "squash", "branch"})

    @property
    def name(self) -> str:
        """Tool name used for MCP registration."""
        return "git_merge"

    def execute(  # type: ignore[override]
        self,
        *,
        branch: str,
        target_branch: str | None = None,
        message: str | None = None,
        path: str = ".",
        **kwargs: object,
    ) -> ToolResult:
        """Squash-merge *branch* into *target_branch*.

        Args:
            branch: The branch to merge in (required).
            target_branch: The branch to merge into (default: the repo's
                resolved default branch).
            message: Commit message for the squash commit. Defaults to
                ``Merge <branch> (squash)``.
            path: Repository path.

        Returns:
            ToolResult with ``merged``, ``into`` and ``message`` on success.
        """
        resolved = Path(path).resolve()
        target_branch = target_branch or resolve_default_branch(resolved)
        msg = message or f"Merge {branch} (squash)"
        try:
            precheck = _check_clean_tree(resolved)
            if precheck is not None:
                return precheck

            failure = _run_merge_steps(branch, target_branch, msg, resolved)
            if failure is not None:
                return failure
        except subprocess.TimeoutExpired as exc:
            return timeout_error_result(exc)

        data: dict[str, object] = {
            "merged": branch,
            "into": target_branch,
            "message": msg,
        }
        return ToolResult(success=True, data=data, text=render_text(data))
name property

Tool name used for MCP registration.

execute(*, branch, target_branch=None, message=None, path='.', **kwargs)

Squash-merge branch into target_branch.

Parameters:

Name Type Description Default
branch str

The branch to merge in (required).

required
target_branch str | None

The branch to merge into (default: the repo's resolved default branch).

None
message str | None

Commit message for the squash commit. Defaults to Merge <branch> (squash).

None
path str

Repository path.

'.'

Returns:

Type Description
ToolResult

ToolResult with merged, into and message on success.

Source code in packages/axm-git/src/axm_git/tools/merge.py
Python
def execute(  # type: ignore[override]
    self,
    *,
    branch: str,
    target_branch: str | None = None,
    message: str | None = None,
    path: str = ".",
    **kwargs: object,
) -> ToolResult:
    """Squash-merge *branch* into *target_branch*.

    Args:
        branch: The branch to merge in (required).
        target_branch: The branch to merge into (default: the repo's
            resolved default branch).
        message: Commit message for the squash commit. Defaults to
            ``Merge <branch> (squash)``.
        path: Repository path.

    Returns:
        ToolResult with ``merged``, ``into`` and ``message`` on success.
    """
    resolved = Path(path).resolve()
    target_branch = target_branch or resolve_default_branch(resolved)
    msg = message or f"Merge {branch} (squash)"
    try:
        precheck = _check_clean_tree(resolved)
        if precheck is not None:
            return precheck

        failure = _run_merge_steps(branch, target_branch, msg, resolved)
        if failure is not None:
            return failure
    except subprocess.TimeoutExpired as exc:
        return timeout_error_result(exc)

    data: dict[str, object] = {
        "merged": branch,
        "into": target_branch,
        "message": msg,
    }
    return ToolResult(success=True, data=data, text=render_text(data))