Skip to content

Commit be1350b

Browse files
cliffhallclaude
andcommitted
fix(git): summarize a working tree whose only change is an untracked file
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: cliffhall <[email protected]>
1 parent eced757 commit be1350b

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

‎src/git/src/mcp_server_git/server.py‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,10 @@ def summarize_changes_prompt(repo: git.Repo, target: str | None = None) -> str:
650650
parts.append(f"Staged changes:\n{_fenced(staged)}")
651651
if unstaged.strip():
652652
parts.append(f"Unstaged changes:\n{_fenced(unstaged)}")
653-
changes = "\n\n".join(parts) if staged.strip() or unstaged.strip() else ""
653+
# The porcelain status is empty only on a clean tree; an untracked file
654+
# alone leaves both diffs empty but is still a change to summarize.
655+
clean = not repo.git.status("--porcelain").strip()
656+
changes = "" if clean else "\n\n".join(parts)
654657
if not changes:
655658
return f"There are no changes {scope} to summarize. Tell the user so."
656659
return (

‎src/git/tests/test_prompts.py‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,16 @@ def test_summarize_only_staged_changes(repo: git.Repo) -> None:
265265
assert "Unstaged changes:" not in text
266266

267267

268+
def test_summarize_only_untracked_files(repo: git.Repo) -> None:
269+
# Both diffs are empty, but the status lists the new file.
270+
(repo_dir(repo) / "untracked.txt").write_text("new\n")
271+
text = summarize_changes_prompt(repo)
272+
assert text.startswith("Summarize the changes in the working tree below")
273+
assert "untracked.txt" in text
274+
assert "Staged changes:" not in text
275+
assert "Unstaged changes:" not in text
276+
277+
268278
def test_summarize_against_a_target_with_no_difference(repo: git.Repo) -> None:
269279
assert summarize_changes_prompt(repo, "HEAD") == (
270280
"There are no changes compared with `HEAD` to summarize. Tell the user so."

0 commit comments

Comments
 (0)