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
24 changes: 24 additions & 0 deletions src/git/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,3 +508,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_with_timestamp_filter_parses_each_commit(test_repository):
"""git_log's timestamp-filtered branch must parse one record per commit.

A trailing %n in the pretty-format emitted 5 newline-delimited fields per
commit while the parser strided by 4, shifting every commit after the first
(Author showed the next commit's hash, etc.).
"""
repo_path = Path(test_repository.working_dir)
for msg in ("second commit", "third commit"):
(repo_path / "test.txt").write_text(msg)
test_repository.index.add(["test.txt"])
test_repository.index.commit(msg)

result = git_log(test_repository, start_timestamp="10 years ago")

assert len(result) == 3
messages = [entry.splitlines()[3][len("Message: "):] for entry in result]
assert messages == ["third commit", "second commit", "initial commit"]
for entry in result:
author = entry.splitlines()[1][len("Author: "):]
# The bug placed the next commit's 40-char hash in the Author field.
assert not (len(author) == 40 and all(c in "0123456789abcdef" for c in author))
Loading