diff --git a/CHANGELOG.md b/CHANGELOG.md index d4b26bdc..abc3ba53 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,11 @@ macOS builds now default to Homebrew's `openssl@3` instead of the removed `opens If `openssl@3` is not installed, run `brew install openssl@3` on existing macOS runners before you update `bench_runner`. +#### 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