@@ -211,7 +211,9 @@ impl App {
211
211
Ok ( ( ) )
212
212
}
213
213
214
- fn clone ( & self , full_name : & str , branch : & str , depth : usize ) -> Result < ( ) , Box < dyn Error > > {
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
+
215
217
assert ! ( cmd(
216
218
"git" ,
217
219
& [
@@ -230,10 +232,18 @@ impl App {
230
232
. wait( ) ?
231
233
. success( ) ) ;
232
234
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
+
233
243
Ok ( ( ) )
234
244
}
235
245
236
- fn list_cpp_files < ' a > ( & ' a self ) -> impl Iterator < Item = String > + ' a {
246
+ fn list_files < ' a > ( & ' a self , includes : & ' a [ Pattern ] , excludes : & ' a [ Pattern ] ) -> impl Iterator < Item = String > + ' a {
237
247
BufReader :: new (
238
248
Command :: new ( "git" )
239
249
. args ( & [ "ls-tree" , "-r" , "HEAD" , "--name-only" , "--full-tree" ] )
@@ -243,26 +253,18 @@ impl App {
243
253
. stdout
244
254
. unwrap ( ) ,
245
255
)
246
- . lines ( )
247
- . map ( |s| s. unwrap ( ) )
248
- . filter ( move |s| self . includes . iter ( ) . any ( |p| p. matches ( & s) ) )
249
- . filter ( move |s| !self . excludes . iter ( ) . any ( |p| p. matches ( & s) ) )
256
+ . lines ( )
257
+ . map ( |s| s. unwrap ( ) )
258
+ . filter ( move |s| includes. iter ( ) . any ( |p| p. matches ( & s) ) )
259
+ . filter ( move |s| !excludes. iter ( ) . any ( |p| p. matches ( & s) ) )
260
+ }
261
+
262
+ fn list_cpp_files < ' a > ( & ' a self ) -> impl Iterator < Item = String > + ' a {
263
+ self . list_files ( & self . includes , & self . excludes )
250
264
}
251
265
252
266
fn list_py_files < ' a > ( & ' a self ) -> impl Iterator < Item = String > + ' a {
253
- BufReader :: new (
254
- Command :: new ( "git" )
255
- . args ( & [ "ls-tree" , "-r" , "HEAD" , "--name-only" , "--full-tree" ] )
256
- . stdout ( Stdio :: piped ( ) )
257
- . spawn ( )
258
- . unwrap ( )
259
- . stdout
260
- . unwrap ( ) ,
261
- )
262
- . lines ( )
263
- . map ( |s| s. unwrap ( ) )
264
- . filter ( move |s| self . py_includes . iter ( ) . any ( |p| p. matches ( & s) ) )
265
- . filter ( move |s| !self . excludes . iter ( ) . any ( |p| p. matches ( & s) ) )
267
+ self . list_files ( & self . py_includes , & self . excludes )
266
268
}
267
269
268
270
fn format_all ( & self ) {
@@ -447,14 +449,17 @@ fn load_payload<T: DeserializeOwned>() -> Result<T, Box<dyn Error>> {
447
449
Ok ( serde_json:: from_str ( & github_event) ?)
448
450
}
449
451
450
- fn ref_to_branch ( r#ref : & str ) -> & str {
451
- let expected_prefix = "refs/heads/" ;
452
- assert ! (
453
- r#ref. starts_with( expected_prefix) ,
454
- "Unexpected push ref: {}" ,
455
- r#ref
456
- ) ;
457
- & r#ref[ expected_prefix. len ( ) ..]
452
+ fn ref_to_branch ( r#ref : & str ) -> Option < ( & str , & str ) > {
453
+ let branch_prefix = "refs/heads/" ;
454
+ let tag_prefix = "refs/tags/" ;
455
+
456
+ if r#ref. starts_with ( branch_prefix) {
457
+ Some ( ( "branch" , & r#ref[ branch_prefix. len ( ) ..] ) )
458
+ } else if r#ref. starts_with ( tag_prefix) {
459
+ Some ( ( "tag" , & r#ref[ tag_prefix. len ( ) ..] ) )
460
+ } else {
461
+ None
462
+ }
458
463
}
459
464
460
465
fn cmd < S : AsRef < OsStr > > ( program : S , args : & [ & str ] ) -> Result < Child , Box < dyn Error > > {
0 commit comments