Fetch base_commit on demand in checkout_commit#748
Open
gggdttt wants to merge 2 commits into
Open
Conversation
Fall back to 'git fetch --depth 1 origin <sha>' when a commit isn't present locally, so a real PR's base_commit (not in the shared clone) can be checked out. Reuses the fetch pattern from clone_at_commit. First step toward accepting real PRs as code-review dataset entries (ADO 643360).
Contributor
There was a problem hiding this comment.
Pull request overview
Adds on-demand fetching when checkout_commit cannot resolve a commit locally, enabling real PR base commits.
Changes:
- Retries checkout after a shallow fetch from
origin. - Adds tests for local and missing commit paths.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/bcbench/operations/git_operations.py |
Adds fetch-and-retry checkout behavior. |
tests/test_git_operations.py |
Tests checkout command sequencing. |
The return code is inspected manually to trigger the on-demand fetch fallback, so check must stay False; make it explicit to satisfy the linter. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 74500e3e-0905-4f26-a2f4-3e6208c4fec2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
checkout_commitnow fetches the target commit fromoriginwhen it isn't already present locally, instead of failing outright.Why
The code-review category checks out
base_commitvia a baregit checkout <sha>(no fetch). That only works because every synthetic entry shares abase_committhat's already in the shared BCApps clone. To let a real PR be added as a dataset entry, the entry'sbase_commit(the PR merge-base) must be resolvable even when it isn't in the local clone.This reuses the exact
git fetch --depth 1 origin <sha>pattern already proven inclone_at_commit. As a side effect it also unblocks modification-type patches (real PRs, not new-files-only), because the base blobs are fetched sogit applycan patch them.First step of Accept real PRs as BC Bench code-review dataset entries (ADO 643360). The ingestion helper (PR pointer → entry) lands in a follow-up PR.
How
git checkoutwithoutcheck=True; on non-zero exit,git fetch --depth 1 origin <sha>then retry the checkout.Tests
tests/test_git_operations.py:test_checkout_commit_present_locally_does_not_fetch— happy path issues onlygit checkout, never fetches.test_checkout_commit_missing_locally_fetches_then_retries— failed checkout triggers fetch + retry in order.uv run python -m pytest tests/test_git_operations.py→ 17 passed.