From ddee69aff8897f37631a2befb853074654746d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurycy=20Paw=C5=82owski-Wiero=C5=84ski?= Date: Thu, 12 Nov 2026 22:10:47 +0100 Subject: [PATCH] Reuse existing checkouts for pinned commits --- CHANGELOG.md | 5 +++++ bench_runner/git.py | 2 +- tests/test_git.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 tests/test_git.py diff --git a/CHANGELOG.md b/CHANGELOG.md index 4aaced4f..c5bb2645 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ override its benchmark job timeout. ### Bugfixes +#### Reuse checkouts at the requested commit + +When a repository is already checked out at the requested full commit hash, +reuse it instead of deleting and cloning it again. + #### Use PGO on weekly builds Since 2.0.0, PGO was not being used on weekly builds. This is now fixed. diff --git a/bench_runner/git.py b/bench_runner/git.py index 0df312fc..dacc48d4 100644 --- a/bench_runner/git.py +++ b/bench_runner/git.py @@ -144,7 +144,7 @@ def clone( dirname = Path(dirname) if dirname.is_dir(): - if is_hash and (dirname / ".git").is_dir() and get_git_hash(dirname) == branch: + if is_hash and (dirname / ".git").is_dir() and get_log("%H", dirname) == branch: # This is a git repo, and the hash matches return util.smart_rmtree(dirname) diff --git a/tests/test_git.py b/tests/test_git.py new file mode 100644 index 00000000..b7b1bb9d --- /dev/null +++ b/tests/test_git.py @@ -0,0 +1,41 @@ +import subprocess + + +import pytest + + +from bench_runner import git + + +@pytest.mark.parametrize("reuse", [True, False]) +def test_clone_existing_checkout(tmp_path, reuse): + repo = tmp_path / "repo" + subprocess.check_call(["git", "init", "--object-format=sha1", repo]) + commit = [ + "git", + "-c", + "user.name=Test", + "-c", + "user.email=test@example.com", + "commit", + "--no-gpg-sign", + "--allow-empty", + "-m", + "Test commit", + ] + subprocess.check_call(commit, cwd=repo) + commit_hash = git.get_log("%H", repo) + checkout = tmp_path / "checkout" + git.clone(checkout, str(repo), branch=commit_hash) + subprocess.check_call(["git", "config", "core.abbrev", "7"], cwd=checkout) + build_output = checkout / "build-output" + build_output.touch() + + if not reuse: + subprocess.check_call(commit, cwd=repo) + commit_hash = git.get_log("%H", repo) + + git.clone(checkout, str(repo), branch=commit_hash) + + assert build_output.exists() == reuse + assert git.get_log("%H", checkout) == commit_hash