Skip to content

Commit dc5ba4c

Browse files
committed
fix(git): raise error on invalid branch type; normalize git_log output format
Two fixes in the git server: 1. git_branch: Invalid branch_type values (not 'local'/'remote'/'all') returned an error string that was silently treated as successful branch output. Now raises ValueError so the caller can properly report the error to the client. 2. git_log: The filtered (--since/--until) and unfiltered paths produced inconsistent output. The unfiltered path used !r (repr) formatting which adds quotes around values (e.g., Commit: 'abc123'), while the filtered path had no quotes. Both paths now use consistent plain formatting. Message field indentation normalized to 4 spaces in both paths.
1 parent d31124c commit dc5ba4c

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def git_log(repo: git.Repo, max_count: int = 10, start_timestamp: Optional[str]
181181
f"Commit: {log_output[i]}\n"
182182
f"Author: {log_output[i+1]}\n"
183183
f"Date: {log_output[i+2]}\n"
184-
f"Message: {log_output[i+3]}\n"
184+
f" {log_output[i+3]}\n"
185185
)
186186
return log
187187
else:
@@ -190,10 +190,10 @@ def git_log(repo: git.Repo, max_count: int = 10, start_timestamp: Optional[str]
190190
log = []
191191
for commit in commits:
192192
log.append(
193-
f"Commit: {commit.hexsha!r}\n"
194-
f"Author: {commit.author!r}\n"
193+
f"Commit: {commit.hexsha}\n"
194+
f"Author: {commit.author}\n"
195195
f"Date: {commit.authored_datetime}\n"
196-
f"Message: {commit.message!r}\n"
196+
f" {commit.message}\n"
197197
)
198198
return log
199199

@@ -297,7 +297,7 @@ def git_branch(repo: git.Repo, branch_type: str, contains: str | None = None, no
297297
case 'all':
298298
b_type = "-a"
299299
case _:
300-
return f"Invalid branch type: {branch_type}"
300+
raise ValueError(f"Invalid branch type: {branch_type}. Expected 'local', 'remote', or 'all'.")
301301

302302
# None value will be auto deleted by GitPython
303303
branch_info = repo.git.branch(b_type, *contains_sha, *not_contains_sha)

0 commit comments

Comments
 (0)