git-cached-diff
Compare staged changes in Git against the last commit to review modifications before finalizing commits.
Instructions
Get a diff between the files in the staging area (the index) and the HEAD
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/git_prompts_mcp_server/server.py:314-320 (registration)Registers the git-cached-diff tool with FastMCP, providing the entry point handler that delegates to GitMethodCollection.@APP.tool( name="git-cached-diff", description="Get a diff between the files in the staging area (the index) and the HEAD", ) async def git_cached_diff_tool() -> list[dict]: return await GIT_METHOD_COLLETION.get_cached_diff_data()
- Core handler method in GitMethodCollection that executes the logic for git-cached-diff by getting diff from HEAD to index.async def get_cached_diff_data(self) -> list[dict]: diff_results = _get_diff_results(self.repo.head.commit, None, self.excludes) return _get_diff_results_as_list_of_dict(diff_results)
- Helper function that computes the actual git diff results between commits or index, applying exclude filters.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
- Helper utility to convert git Diff objects to structured list of dictionaries.def _get_diff_results_as_list_of_dict(diff_results: list[git.Diff]) -> list[dict]: return [ { "a_path": item.a_path or "New Addition", "b_path": item.b_path or "Deleted", "diff": cast(bytes, item.diff).decode("utf-8"), } for item in diff_results ]