Skip to content

Commit 0b28297

Browse files
committed
Merge branch 'fix-panic'
2 parents 1926d08 + e74095e commit 0b28297

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

gix/src/revision/spec/parse/delegate/mod.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,16 @@ impl<'repo> Delegate<'repo> {
203203
for (r, obj) in self.refs.iter().zip(self.objs.iter_mut()) {
204204
if let (Some(ref_), obj_opt @ None) = (r, obj) {
205205
if let Some(id) = ref_.target.try_id().map(ToOwned::to_owned).or_else(|| {
206-
ref_.clone()
207-
.attach(repo)
208-
.peel_to_id_in_place()
209-
.ok()
210-
.map(crate::Id::detach)
206+
match ref_.clone().attach(repo).peel_to_id_in_place() {
207+
Err(err) => {
208+
self.err.push(Error::PeelToId {
209+
name: ref_.name.clone(),
210+
source: err,
211+
});
212+
None
213+
}
214+
Ok(id) => Some(id.detach()),
215+
}
211216
}) {
212217
obj_opt.get_or_insert_with(HashSet::default).insert(id);
213218
};

gix/src/revision/spec/parse/types.rs

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ pub struct Options {
5555
#[derive(Debug, thiserror::Error)]
5656
#[allow(missing_docs)]
5757
pub enum Error {
58+
#[error("Could not peel '{}' to obtain its target", name)]
59+
PeelToId {
60+
name: gix_ref::FullName,
61+
source: reference::peel::Error,
62+
},
5863
#[error("The rev-spec is malformed and misses a ref name")]
5964
Malformed,
6065
#[error("Unborn heads do not have a reflog yet")]
Binary file not shown.

gix/tests/fixtures/make_rev_spec_parse_repos.sh

+8
Original file line numberDiff line numberDiff line change
@@ -417,3 +417,11 @@ git init new
417417
(cd new
418418
baseline '@{1}'
419419
)
420+
421+
git init invalid-head
422+
(cd invalid-head
423+
>file && git add file && git commit -m "init"
424+
rm .git/refs/heads/main
425+
baseline 'HEAD'
426+
baseline 'HEAD:file'
427+
)

gix/tests/revision/spec/from_bytes/mod.rs

+10
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@ fn access_blob_through_tree() {
144144
);
145145
}
146146

147+
#[test]
148+
fn invalid_head() {
149+
let repo = repo("invalid-head").unwrap();
150+
let err = parse_spec("HEAD:file", &repo).unwrap_err();
151+
assert_eq!(err.to_string(), "Could not peel 'HEAD' to obtain its target");
152+
153+
let err = parse_spec("HEAD", &repo).unwrap_err();
154+
assert_eq!(err.to_string(), "The rev-spec is malformed and misses a ref name");
155+
}
156+
147157
#[test]
148158
fn empty_tree_as_full_name() {
149159
let repo = repo("complex_graph").unwrap();

0 commit comments

Comments
 (0)