Skip to content

Fix panic when --policy uses a commit SHA refspec#1414

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/fix-panic-when-policy-uses-sha
Draft

Fix panic when --policy uses a commit SHA refspec#1414
Copilot wants to merge 3 commits intomainfrom
copilot/fix-panic-when-policy-uses-sha

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

gix::clone::PrepareFetch::with_ref_name only accepts symbolic refs (branches/tags) and panics on raw object IDs. Passing a 40-char commit SHA as a refspec causes an unrecoverable panic in gix internals.

weaver registry check --policy 'https://github.com/org/repo.git@d84341cf20a1fef1a833ef44d318c41a770e6e64[policies]'
# thread 'main' panicked at gix-0.81.0/src/clone/fetch/util.rs:217:18

Changes

  • is_commit_sha helper — strict detection of full-length hex SHAs (40-char SHA-1, 64-char SHA-256). Intentionally rejects short hashes to avoid false positives on branch/tag names like deadbeef.
  • SHA-aware clone path in try_from_git_url — when refspec is a commit SHA, skip with_ref_name (which would panic) and clone all refs. Instead of calling main_worktree() (which would checkout the default branch), use a dedicated checkout_sha() helper that checks out the requested commit directly via gix APIs (ObjectId::from_hexfind_objectpeel_to_treeindex_from_treeworktree::state::checkout), avoiding a double checkout. Non-existent SHAs produce a proper GitError instead of a panic.
  • Unit tests for is_commit_sha covering valid/invalid inputs.

Copilot AI linked an issue May 4, 2026 that may be closed by this pull request
Detect full-length hex commit SHAs (SHA-1: 40 chars, SHA-256: 64 chars)
and skip `with_ref_name` which only accepts symbolic refs. Instead,
clone the repo fully and run `git checkout <sha>` after checkout to
switch to the requested commit.

Agent-Logs-Url: https://github.com/open-telemetry/weaver/sessions/80002501-91c1-453a-990b-88b6664f0edf

Co-authored-by: lmolkova <2347409+lmolkova@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic in registry check with commit SHA refspec Fix panic when --policy uses a commit SHA refspec May 4, 2026
Copilot AI requested a review from lmolkova May 4, 2026 18:57
@codecov
Copy link
Copy Markdown

codecov Bot commented May 4, 2026

Codecov Report

❌ Patch coverage is 29.41176% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.3%. Comparing base (69132ef) to head (ef28781).

Files with missing lines Patch % Lines
crates/weaver_common/src/vdir.rs 29.4% 12 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            main   #1414     +/-   ##
=======================================
- Coverage   82.4%   82.3%   -0.2%     
=======================================
  Files        120     120             
  Lines      10092   10108     +16     
=======================================
+ Hits        8320    8323      +3     
- Misses      1772    1785     +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread crates/weaver_common/src/vdir.rs Outdated
// checked out the default branch. Now switch to the requested commit.
if is_sha {
let sha = refspec.as_ref().expect("is_sha implies Some");
let output = std::process::Command::new("git")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@copilot use gix.

every other git op in this crate goes through it, and Cargo.toml:34 already enables worktree-mutation, so the checkout API is on the dep tree for free. Roughly:
repo.rev_parse_single(sha)?, update HEAD, write the worktree. Also lets you
skip main_worktree above on the SHA path and avoid the double checkout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Replaced std::process::Command with pure gix APIs in dcf3e8e. The SHA path now skips main_worktree() entirely and uses ObjectId::from_hexfind_objectpeel_to_treeindex_from_treeworktree::state::checkout to write the worktree directly, avoiding the double checkout.

Use gix's ObjectId::from_hex, find_object, peel_to_tree, index_from_tree,
and worktree::state::checkout instead of shelling out to `git checkout`.
For the SHA path, skip main_worktree() entirely and checkout the requested
commit directly, avoiding a double checkout.

Agent-Logs-Url: https://github.com/open-telemetry/weaver/sessions/3f847f32-e10a-4518-8deb-b4f2d0d99f88

Co-authored-by: lmolkova <2347409+lmolkova@users.noreply.github.com>
let repo = checkout.persist();
Self::checkout_sha(&repo, sha, url)?;
} else {
let _repo = checkout
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.

Why is the result unused? Please add a comment or rationale behind what this is doing - is it for an effect? if so comment on what we expect to have happen and why we're not returning a value.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Panic when --policy uses a commit SHA refspec

3 participants