From f1d5d532f8188071f23c38e4a463f872d4994f6b Mon Sep 17 00:00:00 2001 From: Raunak Date: Mon, 30 Nov 2026 03:26:18 -0500 Subject: [PATCH 1/2] fix(git): preserve whitespace in repository paths --- py/src/braintrust/gitutil.py | 5 ++-- py/src/braintrust/test_gitutil.py | 39 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/py/src/braintrust/gitutil.py b/py/src/braintrust/gitutil.py index 329618829..726365464 100644 --- a/py/src/braintrust/gitutil.py +++ b/py/src/braintrust/gitutil.py @@ -61,11 +61,12 @@ def _is_dirty(repo_path): @_cache(1) def _current_repo(): try: - return _git_output(["rev-parse", "--show-toplevel"]).strip() + # _git_output removes the terminating newline without changing the path. + return _git_output(["rev-parse", "--show-toplevel"]) except (OSError, subprocess.CalledProcessError): try: if _git_output(["rev-parse", "--is-bare-repository"]).strip() == "true": - return _git_output(["rev-parse", "--absolute-git-dir"]).strip() + return _git_output(["rev-parse", "--absolute-git-dir"]) except (OSError, subprocess.CalledProcessError): pass return None diff --git a/py/src/braintrust/test_gitutil.py b/py/src/braintrust/test_gitutil.py index 45a06a49f..6b4559e04 100644 --- a/py/src/braintrust/test_gitutil.py +++ b/py/src/braintrust/test_gitutil.py @@ -68,3 +68,42 @@ def test_repo_info_returns_none_when_git_cannot_be_resolved(monkeypatch: pytest. def test_get_repo_info_without_settings_returns_none(): """Direct call to get_repo_info with settings=None should return None.""" assert gitutil.get_repo_info(None) is None + + +@pytest.mark.skipif(os.name == "nt", reason="Windows does not support trailing spaces in ordinary directory paths") +@pytest.mark.parametrize("bare", [False, True], ids=["worktree", "bare"]) +def test_repo_info_handles_repository_path_with_trailing_space(tmp_path, monkeypatch, bare): + repo = tmp_path / "eval project " + repo.mkdir() + worktree = tmp_path / "source" if bare else repo + worktree.mkdir(exist_ok=True) + subprocess.run(["git", "init"], cwd=worktree, check=True, capture_output=True) + + subprocess.run( + [ + "git", + "-c", + "user.name=Eval Test", + "-c", + "user.email=eval@example.invalid", + "commit", + "--allow-empty", + "-m", + "Initial eval baseline", + ], + cwd=worktree, + check=True, + capture_output=True, + ) + if bare: + subprocess.run( + ["git", "clone", "--bare", str(worktree), str(repo)], cwd=worktree, check=True, capture_output=True + ) + expected_commit = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=repo, text=True).strip() + monkeypatch.chdir(repo) + + info = gitutil.get_repo_info(gitutil.GitMetadataSettings(collect="all")) + + assert info is not None + assert info.commit == expected_commit + assert info.commit_message == "Initial eval baseline" From e90731141d0c2bc25c963fa735594d3ac75a8446 Mon Sep 17 00:00:00 2001 From: Raunak Kumar Pandey <65064180+raunakpandey1@users.noreply.github.com> Date: Mon, 30 Nov 2026 03:31:43 -0500 Subject: [PATCH 2/2] Update py/src/braintrust/test_gitutil.py Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com> --- py/src/braintrust/test_gitutil.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/py/src/braintrust/test_gitutil.py b/py/src/braintrust/test_gitutil.py index 6b4559e04..ed74a86cf 100644 --- a/py/src/braintrust/test_gitutil.py +++ b/py/src/braintrust/test_gitutil.py @@ -86,6 +86,8 @@ def test_repo_info_handles_repository_path_with_trailing_space(tmp_path, monkeyp "user.name=Eval Test", "-c", "user.email=eval@example.invalid", + "-c", + "commit.gpgsign=false", "commit", "--allow-empty", "-m",