Skip to content

Commit

Permalink
Merge branch 'fix-panic'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Aug 11, 2024
2 parents 1926d08 + e74095e commit 0b28297
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
15 changes: 10 additions & 5 deletions gix/src/revision/spec/parse/delegate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,16 @@ impl<'repo> Delegate<'repo> {
for (r, obj) in self.refs.iter().zip(self.objs.iter_mut()) {
if let (Some(ref_), obj_opt @ None) = (r, obj) {
if let Some(id) = ref_.target.try_id().map(ToOwned::to_owned).or_else(|| {
ref_.clone()
.attach(repo)
.peel_to_id_in_place()
.ok()
.map(crate::Id::detach)
match ref_.clone().attach(repo).peel_to_id_in_place() {
Err(err) => {
self.err.push(Error::PeelToId {
name: ref_.name.clone(),
source: err,
});
None
}
Ok(id) => Some(id.detach()),
}
}) {
obj_opt.get_or_insert_with(HashSet::default).insert(id);
};
Expand Down
5 changes: 5 additions & 0 deletions gix/src/revision/spec/parse/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ pub struct Options {
#[derive(Debug, thiserror::Error)]
#[allow(missing_docs)]
pub enum Error {
#[error("Could not peel '{}' to obtain its target", name)]
PeelToId {
name: gix_ref::FullName,
source: reference::peel::Error,
},
#[error("The rev-spec is malformed and misses a ref name")]
Malformed,
#[error("Unborn heads do not have a reflog yet")]
Expand Down
Binary file not shown.
8 changes: 8 additions & 0 deletions gix/tests/fixtures/make_rev_spec_parse_repos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,11 @@ git init new
(cd new
baseline '@{1}'
)
git init invalid-head
(cd invalid-head
>file && git add file && git commit -m "init"
rm .git/refs/heads/main
baseline 'HEAD'
baseline 'HEAD:file'
)
10 changes: 10 additions & 0 deletions gix/tests/revision/spec/from_bytes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,16 @@ fn access_blob_through_tree() {
);
}

#[test]
fn invalid_head() {
let repo = repo("invalid-head").unwrap();
let err = parse_spec("HEAD:file", &repo).unwrap_err();
assert_eq!(err.to_string(), "Could not peel 'HEAD' to obtain its target");

let err = parse_spec("HEAD", &repo).unwrap_err();
assert_eq!(err.to_string(), "The rev-spec is malformed and misses a ref name");
}

#[test]
fn empty_tree_as_full_name() {
let repo = repo("complex_graph").unwrap();
Expand Down

0 comments on commit 0b28297

Please sign in to comment.