File tree Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Expand file tree Collapse file tree 2 files changed +43
-1
lines changed Original file line number Diff line number Diff line change @@ -80,7 +80,13 @@ fn sync(
8080 if !opts. no_delete {
8181 for entry in canonical_destination. read_dir ( ) ? {
8282 let entry = entry?;
83- to_remove. insert ( entry. path ( ) ) ;
83+ if !entry
84+ . file_name ( )
85+ . to_str ( )
86+ . map_or ( false , |s| s. starts_with ( '.' ) )
87+ {
88+ to_remove. insert ( entry. path ( ) ) ;
89+ }
8490 }
8591 }
8692
Original file line number Diff line number Diff line change @@ -501,3 +501,39 @@ fn depend_on_vendor_dir_not_deleted() {
501501 p. cargo ( "vendor --respect-source-config" ) . run ( ) ;
502502 assert ! ( p. root( ) . join( "vendor/libc" ) . is_dir( ) ) ;
503503}
504+
505+ #[ cargo_test]
506+ fn ignore_hidden ( ) {
507+ // Don't delete files starting with `.`
508+ Package :: new ( "bar" , "0.1.0" ) . publish ( ) ;
509+ let p = project ( )
510+ . file (
511+ "Cargo.toml" ,
512+ r#"
513+ [package]
514+ name = "foo"
515+ version = "1.0.0"
516+ [dependencies]
517+ bar = "0.1.0"
518+ "# ,
519+ )
520+ . file ( "src/lib.rs" , "" )
521+ . build ( ) ;
522+ p. cargo ( "vendor --respect-source-config" ) . run ( ) ;
523+ // Add a `.git` directory.
524+ let repo = git:: init ( & p. root ( ) . join ( "vendor" ) ) ;
525+ git:: add ( & repo) ;
526+ git:: commit ( & repo) ;
527+ assert ! ( p. root( ) . join( "vendor/.git" ) . exists( ) ) ;
528+ // Vendor again, shouldn't change anything.
529+ p. cargo ( "vendor --respect-source-config" ) . run ( ) ;
530+ // .git should not be removed.
531+ assert ! ( p. root( ) . join( "vendor/.git" ) . exists( ) ) ;
532+ // And just for good measure, make sure no files changed.
533+ let mut opts = git2:: StatusOptions :: new ( ) ;
534+ assert ! ( repo
535+ . statuses( Some ( & mut opts) )
536+ . unwrap( )
537+ . iter( )
538+ . all( |status| status. status( ) == git2:: Status :: CURRENT ) ) ;
539+ }
You can’t perform that action at this time.
0 commit comments