Skip to content

Commit a67e3b0

Browse files
authored
fix: mcp_server_git: correct add logic for ["."] (#2379)
1 parent c9f7d02 commit a67e3b0

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

src/git/src/mcp_server_git/server.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ def git_commit(repo: git.Repo, message: str) -> str:
115115
return f"Changes committed successfully with hash {commit.hexsha}"
116116

117117
def git_add(repo: git.Repo, files: list[str]) -> str:
118-
repo.index.add(files)
118+
if files == ["."]:
119+
repo.git.add(".")
120+
else:
121+
repo.index.add(files)
119122
return "Files staged successfully"
120123

121124
def git_reset(repo: git.Repo) -> str:

src/git/tests/test_server.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from pathlib import Path
33
import git
4-
from mcp_server_git.server import git_checkout, git_branch
4+
from mcp_server_git.server import git_checkout, git_branch, git_add
55
import shutil
66

77
@pytest.fixture
@@ -68,3 +68,26 @@ def test_git_branch_not_contains(test_repository):
6868
result = git_branch(test_repository, "local", not_contains=commit.hexsha)
6969
assert "another-feature-branch" not in result
7070
assert "master" in result
71+
72+
def test_git_add_all_files(test_repository):
73+
file_path = Path(test_repository.working_dir) / "all_file.txt"
74+
file_path.write_text("adding all")
75+
76+
result = git_add(test_repository, ["."])
77+
78+
staged_files = [item.a_path for item in test_repository.index.diff("HEAD")]
79+
assert "all_file.txt" in staged_files
80+
assert result == "Files staged successfully"
81+
82+
def test_git_add_specific_files(test_repository):
83+
file1 = Path(test_repository.working_dir) / "file1.txt"
84+
file2 = Path(test_repository.working_dir) / "file2.txt"
85+
file1.write_text("file 1 content")
86+
file2.write_text("file 2 content")
87+
88+
result = git_add(test_repository, ["file1.txt"])
89+
90+
staged_files = [item.a_path for item in test_repository.index.diff("HEAD")]
91+
assert "file1.txt" in staged_files
92+
assert "file2.txt" not in staged_files
93+
assert result == "Files staged successfully"

0 commit comments

Comments
 (0)