Skip to content

Fetch base_commit on demand in checkout_commit#748

Open
gggdttt wants to merge 2 commits into
mainfrom
fix/codereview-fetch-base-commit
Open

Fetch base_commit on demand in checkout_commit#748
gggdttt wants to merge 2 commits into
mainfrom
fix/codereview-fetch-base-commit

Conversation

@gggdttt

@gggdttt gggdttt commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

What

checkout_commit now fetches the target commit from origin when it isn't already present locally, instead of failing outright.

Why

The code-review category checks out base_commit via a bare git checkout <sha> (no fetch). That only works because every synthetic entry shares a base_commit that's already in the shared BCApps clone. To let a real PR be added as a dataset entry, the entry's base_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 in clone_at_commit. As a side effect it also unblocks modification-type patches (real PRs, not new-files-only), because the base blobs are fetched so git apply can 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

  • Run the initial git checkout without check=True; on non-zero exit, git fetch --depth 1 origin <sha> then retry the checkout.
  • Commit-present path is unchanged (single checkout, no network).

Tests

tests/test_git_operations.py:

  • test_checkout_commit_present_locally_does_not_fetch — happy path issues only git 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.

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).
Copilot AI review requested due to automatic review settings July 23, 2026 09:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copilot AI review requested due to automatic review settings July 23, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants