Skip to content

fix(git): stop reporting staged files when nothing was staged - #4764

Open
ConnorMoss02 wants to merge 2 commits into
modelcontextprotocol:mainfrom
ConnorMoss02:fix/git-add-nothing
Open

fix(git): stop reporting staged files when nothing was staged#4764
ConnorMoss02 wants to merge 2 commits into
modelcontextprotocol:mainfrom
ConnorMoss02:fix/git-add-nothing

Conversation

@ConnorMoss02

Copy link
Copy Markdown
Contributor

Closes #4763

git_add returns the constant Files staged successfully regardless of what the index took. git add exits 0 when it stages nothing, so two calls report success having done nothing:

  • files: [] runs git add -- with no pathspec, a no-op. The schema put no minimum on the list.
  • files: ["."] on a tree with no changes stages nothing.
tree clean?      True
git_add(["."]) -> "Files staged successfully"
actually staged: ''

A nonexistent path is unaffected — git add -- nope.txt already raises.

Paired with #4762, an agent can stage nothing, commit nothing, and report the work as committed.

Fix

  • Reject an empty list, at the schema (min_length=1) and in the function, since it can never stage anything.
  • Read the outcome back from the index rather than assuming it from the exit status.

The success string is byte-identical when it is true, so callers matching on it are unaffected.

Tests

Three: the empty list rejected at the function and at the schema, and ["."] on an unchanged tree no longer claiming success. All three fail with the source change reverted. 50 passed in src/git.

git_add returned the constant "Files staged successfully" regardless of
what the index took. `git add` exits 0 when it stages nothing, so two
callers got a success they could not check:

- files: [] runs `git add --` with no pathspec, a no-op
- files: ["."] on a tree with no changes stages nothing

Paired with git_commit, an agent could stage nothing, commit nothing, and
report the work as committed.

Rejects an empty list at the schema and in the function, and reads the
outcome back from the index instead of assuming it from the exit status.
The success string is unchanged when it is true.
Index entry keys are PathLike, and a diff entry can leave either path
unset, so the helper returned list[PathLike] and list[str | None] where
list[str] was declared.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

git_add reports 'Files staged successfully' when nothing was staged

1 participant