Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/git/src/mcp_server_git/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def git_log(repo: git.Repo, max_count: int = 10, start_timestamp: Optional[str]
args.extend(['--since', start_timestamp])
if end_timestamp:
args.extend(['--until', end_timestamp])
args.extend(['--format=%H%n%an%n%ad%n%s%n'])
args.extend(['--format=%H%n%an%n%ad%n%s'])

log_output = repo.git.log(*args).split('\n')

Expand Down
24 changes: 24 additions & 0 deletions src/git/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,3 +482,27 @@ def test_git_branch_rejects_contains_flag_injection(test_repository):

with pytest.raises(BadName):
git_branch(test_repository, "local", not_contains="--exec=evil")


def test_git_log_timestamp_filter_aligns_commit_fields(tmp_path):
"""git_log with a timestamp filter must not scramble fields across commits."""
repo_path = tmp_path / "ts_repo"
repo = git.Repo.init(repo_path)
author = git.Actor("Tester", "tester@example.com")
(repo_path / "f.txt").write_text("a")
repo.index.add(["f.txt"])
repo.index.commit("first commit", author=author, commit_date="2024-01-10T10:00:00")
(repo_path / "f.txt").write_text("b")
repo.index.add(["f.txt"])
repo.index.commit("second commit", author=author, commit_date="2024-01-20T10:00:00")

result = git_log(repo, start_timestamp="2024-01-01")

assert len(result) == 2
joined = "\n".join(result)
# Both subjects appear in Message fields (none dropped or shifted).
assert "Message: second commit" in joined
assert "Message: first commit" in joined
# Author appears only in Author fields, never shifted into Commit/Date.
assert "Commit: Tester" not in joined
assert "Author: Tester" in joined
Loading