Skip to content

git_add reports 'Files staged successfully' when nothing was staged #4763

Description

@ConnorMoss02

Describe the bug

git_add returns the constant string Files staged successfully regardless of what the index actually took.

src/git/src/mcp_server_git/server.py:132-153:

def git_add(repo: git.Repo, files: list[str]) -> str:
    if files == ["."]:
        repo.git.add(".")
    else:
        ...
        repo.git.add("--", *files)
    return "Files staged successfully"

git add exits 0 when it stages nothing, so two calls report success having done nothing:

  • files: [] runs git add -- with no pathspec, which is a no-op. The schema puts no minimum on the list.
  • files: ["."] on a tree with no changes stages nothing.

A nonexistent path is not affected — git add -- nope.txt already fails with "pathspec did not match any files".

The practical failure: an agent computes a file list that comes back empty — a filter, a glob, a diff parse that matched nothing — and passes it. It is told the files are staged. Paired with #4762, it can then stage nothing, commit nothing, and report the work as committed.

To Reproduce

import git
repo = git.Repo(".")             # a tracked file, edited but not staged

repo.git.add("--")               # files: []
repo.git.diff("--cached", "--name-only")   # '' — nothing staged
# git_add returns: "Files staged successfully"

Same on a clean tree with files: ["."]:

tree clean?      True
git_add(["."]) -> "Files staged successfully"
actually staged: ''

Expected behavior

An empty files list should be rejected, since it can never stage anything. Otherwise the reported outcome should reflect what the index actually holds, rather than the exit status.

Additional context

No test covers either case; the existing git_add tests all stage a real change first.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions