@@ -211,9 +211,7 @@ impl App {
211
211
Ok ( ( ) )
212
212
}
213
213
214
- fn clone ( & self , full_name : & str , r#ref : & str , depth : usize ) -> Result < ( ) , Box < dyn Error > > {
215
- let ( ref_type, ref_name) = ref_to_branch ( r#ref) . ok_or ( "Invalid reference" ) ?;
216
-
214
+ fn clone ( & self , full_name : & str , branch : & str , depth : usize ) -> Result < ( ) , Box < dyn Error > > {
217
215
assert ! ( cmd(
218
216
"git" ,
219
217
& [
@@ -232,14 +230,6 @@ impl App {
232
230
. wait( ) ?
233
231
. success( ) ) ;
234
232
235
- if ref_type == "tag" {
236
- // Checkout the commit associated with the tag
237
- assert ! ( cmd( "git" , & [ "checkout" , ref_name] ) ?. wait( ) ?. success( ) ) ;
238
- } else {
239
- // Checkout the branch
240
- assert ! ( cmd( "git" , & [ "checkout" , ref_name] ) ?. wait( ) ?. success( ) ) ;
241
- }
242
-
243
233
Ok ( ( ) )
244
234
}
245
235
@@ -420,7 +410,7 @@ FLAGS:
420
410
421
411
fn check ( & self , _matches : & ArgMatches ) -> Result < ( ) , Box < dyn Error > > {
422
412
let payload: GitHubPushEvent = load_payload ( ) ?;
423
- let branch = ref_to_branch ( & payload. r#ref ) ;
413
+ let branch = ref_to_branch ( & payload. r#ref ) . ok_or ( "Invalid reference" ) ? ;
424
414
self . clone ( & payload. repository . full_name , branch, 1 ) ?;
425
415
self . format_all ( ) ;
426
416
@@ -449,16 +439,16 @@ fn load_payload<T: DeserializeOwned>() -> Result<T, Box<dyn Error>> {
449
439
Ok ( serde_json:: from_str ( & github_event) ?)
450
440
}
451
441
452
- fn ref_to_branch ( r#ref : & str ) -> Option < ( & str , & str ) > {
442
+ fn ref_to_branch ( r#ref : & str ) -> & str {
453
443
let branch_prefix = "refs/heads/" ;
454
444
let tag_prefix = "refs/tags/" ;
455
445
456
446
if r#ref. starts_with ( branch_prefix) {
457
- Some ( ( "branch" , & r#ref[ branch_prefix. len ( ) ..] ) )
447
+ & r#ref[ branch_prefix. len ( ) ..]
458
448
} else if r#ref. starts_with ( tag_prefix) {
459
- Some ( ( "tag" , & r#ref[ tag_prefix. len ( ) ..] ) )
449
+ & r#ref[ tag_prefix. len ( ) ..]
460
450
} else {
461
- None
451
+ r#ref
462
452
}
463
453
}
464
454
0 commit comments