@@ -171,7 +171,11 @@ pub(in crate::fetch::refs) fn parse_v2(line: &str) -> Result<Ref, Error> {
171
171
let mut tokens = trimmed. splitn ( 3 , ' ' ) ;
172
172
match ( tokens. next ( ) , tokens. next ( ) ) {
173
173
( Some ( hex_hash) , Some ( path) ) => {
174
- let id = git_hash:: ObjectId :: from_hex ( hex_hash. as_bytes ( ) ) ?;
174
+ let id = if hex_hash == "unborn" {
175
+ None
176
+ } else {
177
+ Some ( git_hash:: ObjectId :: from_hex ( hex_hash. as_bytes ( ) ) ?)
178
+ } ;
175
179
if path. is_empty ( ) {
176
180
return Err ( Error :: MalformedV2RefLine ( trimmed. to_owned ( ) ) ) ;
177
181
}
@@ -186,17 +190,24 @@ pub(in crate::fetch::refs) fn parse_v2(line: &str) -> Result<Ref, Error> {
186
190
"peeled" => Ref :: Peeled {
187
191
full_ref_name : path. into ( ) ,
188
192
object : git_hash:: ObjectId :: from_hex ( value. as_bytes ( ) ) ?,
189
- tag : id,
193
+ tag : id. ok_or_else ( || Error :: InvariantViolation {
194
+ message : "got 'unborn' as tag target" ,
195
+ } ) ?,
190
196
} ,
191
197
"symref-target" => match value {
192
198
"(null)" => Ref :: Direct {
193
199
full_ref_name : path. into ( ) ,
194
- object : id,
200
+ object : id. ok_or_else ( || Error :: InvariantViolation {
201
+ message : "got 'unborn' while (null) was a symref target" ,
202
+ } ) ?,
195
203
} ,
196
- name => Ref :: Symbolic {
197
- full_ref_name : path. into ( ) ,
198
- object : id,
199
- target : name. into ( ) ,
204
+ name => match id {
205
+ Some ( id) => Ref :: Symbolic {
206
+ full_ref_name : path. into ( ) ,
207
+ object : id,
208
+ target : name. into ( ) ,
209
+ } ,
210
+ None => Ref :: Unborn { target : name. into ( ) } ,
200
211
} ,
201
212
} ,
202
213
_ => {
@@ -211,7 +222,9 @@ pub(in crate::fetch::refs) fn parse_v2(line: &str) -> Result<Ref, Error> {
211
222
}
212
223
} else {
213
224
Ref :: Direct {
214
- object : id,
225
+ object : id. ok_or_else ( || Error :: InvariantViolation {
226
+ message : "got 'unborn' as object name of direct reference" ,
227
+ } ) ?,
215
228
full_ref_name : path. into ( ) ,
216
229
}
217
230
} )
0 commit comments