git-diff
Compare Git changes between HEAD and an ancestor branch or commit to analyze code modifications for review or documentation.
Instructions
Get a diff between the HEAD and the ancestor branch or commit
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ancestor | Yes | The ancestor commit hash or branch name |
Implementation Reference
- The primary handler function for the 'git-diff' tool. It validates the ancestor input and delegates to GitMethodCollection.get_diff_data to retrieve and format the diff.ancestor: str = Field(..., description="The ancestor commit hash or branch name"), ) -> list[dict[str, str]]: return await GIT_METHOD_COLLETION.get_diff_data(ancestor)
- src/git_prompts_mcp_server/server.py:381-384 (registration)Registers the 'git-diff' tool with FastMCP server, including name and description.name="git-diff", description="Get a diff between the HEAD and the ancestor branch or commit", ) async def git_diff_tool(
- Pydantic schema definition for the 'ancestor' input parameter of the git-diff tool.) -> list[dict[str, str]]:
- Helper method in GitMethodCollection that computes git diff between ancestor commit and HEAD, applies excludes, and returns formatted list of dicts.async def get_diff_data(self, ancestor: str) -> list[dict[str, str]]: if not ancestor: raise ValueError("Ancestor argument required") diff_results = _get_diff_results(self.repo.commit(ancestor), self.repo.head.commit, self.excludes) return _get_diff_results_as_list_of_dict(diff_results)
- Core helper function that generates git diff results between two commits (or index), filters by exclude patterns.def _get_diff_results( source_commit: git.Commit, target_commit: git.Commit | None, excludes: list[str] ) -> list[git.Diff]: if target_commit is None: # Note: source_commit.diff() compares source with the index (staged changes) # source_commit.diff(None) compares source with the working tree diff_results = source_commit.diff(create_patch=True) else: diff_results = source_commit.diff(target_commit, create_patch=True) for exclude_pattern in excludes: diff_results = [ item for item in diff_results if not fnmatch(item.a_path or "", exclude_pattern) and not fnmatch(item.b_path or "", exclude_pattern) ] return diff_results