diff --git a/src/main.rs b/src/main.rs index a31da37..9c1fc86 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,10 +25,15 @@ fn main() -> anyhow::Result<()> { if let Some(subtree) = &arguments.subtree { let entry = current_tree .lookup_entry_by_path(subtree)? - .expect("sub-tree not found"); - if entry.mode().is_tree() { - current_tree = repository.find_tree(entry.id())?; + .ok_or_else(|| anyhow::anyhow!("Failed to find subtree: {subtree:?}"))?; + + if !entry.mode().is_tree() { + Err(anyhow::anyhow!("{subtree:?} is not a subtree"))?; } + + current_tree = repository + .find_tree(entry.id()) + .context("Searching for subtree entry's tree")?; } // Build a set of the entry file names we are interested in. @@ -37,7 +42,7 @@ fn main() -> anyhow::Result<()> { interested.insert(entry?.filename().to_owned()); } - let name_pad = interested + let name_pad = 2 + interested .iter() .fold(0, |len, filename| std::cmp::max(len, filename.len())); @@ -92,9 +97,15 @@ fn main() -> anyhow::Result<()> { } break; }; - if entry.mode().is_tree() { - parent_tree = repository.find_tree(entry.id())?; + if !entry.mode().is_tree() { + // The subtree is no longer a subtree in this revision. Assume any + // remaining entries of interest belong to this commit. + for entry in interested.drain() { + output(entry.as_bstr(), ¤t_commit)?; + } + break; } + parent_tree = repository.find_tree(entry.id())?; } let mut scanner = EntryScanner::new(current_tree.iter(), parent_tree.iter())?; @@ -257,7 +268,7 @@ impl ResolveRevSpec for Repository { Err(_) => { let id = self .find_reference(spec) - .context("Failed to resolve reference in repository {}")? + .context("Failed to resolve reference in repository")? .into_fully_peeled_id()?; self.find_commit(id)