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 @@ -169,7 +169,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
32 changes: 32 additions & 0 deletions src/git/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,38 @@ def test_git_log_default(test_repository):
assert len(result) >= 1
assert "initial commit" in result[0]

def test_git_log_with_timestamp_filter(test_repository):
"""Date-filtered git_log must map fields correctly for every commit, not
just the first. Regression for a trailing ``%n`` in the pretty-format that
emitted a blank line per commit, shifting every commit after the first by
one field (the hash showed up under ``Author:``, the date under
``Message:``, and a commit could be dropped)."""
for i in range(3):
file_path = Path(test_repository.working_dir) / f"ts_log_{i}.txt"
file_path.write_text(f"content {i}")
test_repository.index.add([f"ts_log_{i}.txt"])
test_repository.index.commit(f"timestamped commit {i}")

# initial commit + 3 new commits all fall after this floor
result = git_log(test_repository, max_count=10, start_timestamp="2000-01-01")

assert isinstance(result, list)
assert len(result) == 4

messages = []
for entry in result:
lines = entry.splitlines()
assert lines[0].startswith("Commit: ")
assert lines[1].startswith("Author: ")
assert lines[2].startswith("Date: ")
assert lines[3].startswith("Message: ")
messages.append(lines[3][len("Message: "):])

# Under the bug these messages land in the wrong field for commits 2..n.
assert "timestamped commit 2" in messages
assert "timestamped commit 1" in messages
assert "initial commit" in messages

def test_git_create_branch(test_repository):
result = git_create_branch(test_repository, "new-feature-branch")

Expand Down
Loading