File tree Expand file tree Collapse file tree 5 files changed +33
-5
lines changed Expand file tree Collapse file tree 5 files changed +33
-5
lines changed Original file line number Diff line number Diff 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 } ;
Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ pub struct Options {
5555#[ derive( Debug , thiserror:: Error ) ]
5656#[ allow( missing_docs) ]
5757pub 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" ) ]
Original file line number Diff line number Diff 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+ )
Original file line number Diff line number Diff 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]
148158fn empty_tree_as_full_name ( ) {
149159 let repo = repo ( "complex_graph" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments