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
5 changes: 4 additions & 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,10 @@ 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'])
# No trailing %n: git already separates entries with a newline, so a
# trailing %n would emit 5 lines per commit and break the groups-of-4
# parsing below for every commit after the first.
args.extend(['--format=%H%n%an%n%ad%n%s'])

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

Expand Down
19 changes: 19 additions & 0 deletions src/git/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,25 @@ def test_git_log(test_repository):
assert "Date:" in result[0]
assert "Message:" in result[0]

def test_git_log_with_date_filter(test_repository):
"""Every commit on the date-filtered path parses into aligned fields."""
for i in range(3):
file_path = Path(test_repository.working_dir) / f"log_filter_{i}.txt"
file_path.write_text(f"content {i}")
test_repository.index.add([f"log_filter_{i}.txt"])
test_repository.index.commit(f"commit {i}")

result = git_log(test_repository, start_timestamp="2000-01-01")

# initial commit fixture + 3 above
assert len(result) == 4
for i, entry in enumerate(reversed(result[:3])):
lines = entry.splitlines()
assert lines[0].startswith("Commit: ") and len(lines[0]) == len("Commit: ") + 40
assert lines[1].startswith("Author: ") and lines[1] != "Author: "
assert lines[2].startswith("Date: ")
assert lines[3] == f"Message: commit {i}"

def test_git_log_default(test_repository):
result = git_log(test_repository)

Expand Down
Loading