File tree 5 files changed +33
-5
lines changed
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> {
203
203
for ( r, obj) in self . refs . iter ( ) . zip ( self . objs . iter_mut ( ) ) {
204
204
if let ( Some ( ref_) , obj_opt @ None ) = ( r, obj) {
205
205
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
+ }
211
216
} ) {
212
217
obj_opt. get_or_insert_with ( HashSet :: default) . insert ( id) ;
213
218
} ;
Original file line number Diff line number Diff line change @@ -55,6 +55,11 @@ pub struct Options {
55
55
#[ derive( Debug , thiserror:: Error ) ]
56
56
#[ allow( missing_docs) ]
57
57
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
+ } ,
58
63
#[ error( "The rev-spec is malformed and misses a ref name" ) ]
59
64
Malformed ,
60
65
#[ 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
417
417
(cd new
418
418
baseline '@{1}'
419
419
)
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() {
144
144
) ;
145
145
}
146
146
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
+
147
157
#[ test]
148
158
fn empty_tree_as_full_name ( ) {
149
159
let repo = repo ( "complex_graph" ) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments