From 54ce2a230f9ef7bbd47edb5e2e6fb85106a7b1b3 Mon Sep 17 00:00:00 2001 From: Vui-Chee Date: Sat, 7 Mar 2026 15:20:49 +0800 Subject: [PATCH] indexer: handle missing parent objects in shallow clones and root commits When `semcode-index --source` is run without `--git`, it auto-detects HEAD and constructs the range `HEAD^..HEAD`. On a shallow clone or a repo initialized from a tarball (single root commit), `HEAD^` refers to a parent object that doesn't exist in the local object store, causing gix to error with "An object with id ... could not be found". Fix `list_shas_in_range` to catch this error and fall back to returning just the target commit SHA, so indexing proceeds normally with the single HEAD commit. Co-Authored-By: Claude Sonnet 4.6 (1M context) --- src/indexer.rs | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/indexer.rs b/src/indexer.rs index 58675bd..3983059 100644 --- a/src/indexer.rs +++ b/src/indexer.rs @@ -116,12 +116,24 @@ pub fn list_shas_in_range(repo: &gix::Repository, range: &str) -> Result { + let from_id = from_commit.id().detach(); + repo.rev_walk([to_id]) + .with_hidden([from_id]) + .sorting(Sorting::ByCommitTime(Default::default())) + .all()? + } + Err(e) => { + // Parent commit not found in local object store (shallow clone or root commit). + // Fall back to returning just the single target commit. + info!( + "Could not resolve '{}' ({}); falling back to single-commit indexing", + from_spec, e + ); + return Ok(vec![to_id.to_string()]); + } + } }; let mut shas = Vec::new();