11use std:: fs:: File ;
22
3- use git2;
4-
53use crate :: support:: git;
64use crate :: support:: { basic_manifest, clippy_is_available, is_nightly, project} ;
75
@@ -710,15 +708,8 @@ fn warns_if_no_vcs_detected() {
710708
711709#[ cargo_test]
712710fn warns_about_dirty_working_directory ( ) {
713- let p = project ( ) . file ( "src/lib.rs" , "pub fn foo() {}" ) . build ( ) ;
711+ let p = git :: new ( "foo" , |p| p . file ( "src/lib.rs" , "pub fn foo() {}" ) ) ;
714712
715- let repo = git2:: Repository :: init ( & p. root ( ) ) . unwrap ( ) ;
716- let mut cfg = t ! ( repo. config( ) ) ;
717- t ! ( cfg. set_str( "user.email" , "foo@bar.com" ) ) ;
718- t ! ( cfg. set_str( "user.name" , "Foo Bar" ) ) ;
719- drop ( cfg) ;
720- git:: add ( & repo) ;
721- git:: commit ( & repo) ;
722713 File :: create ( p. root ( ) . join ( "src/lib.rs" ) ) . unwrap ( ) ;
723714
724715 p. cargo ( "fix" )
@@ -741,15 +732,8 @@ commit the changes to these files:
741732
742733#[ cargo_test]
743734fn warns_about_staged_working_directory ( ) {
744- let p = project ( ) . file ( "src/lib.rs" , "pub fn foo() {}" ) . build ( ) ;
735+ let ( p , repo ) = git :: new_repo ( "foo" , |p| p . file ( "src/lib.rs" , "pub fn foo() {}" ) ) ;
745736
746- let repo = git2:: Repository :: init ( & p. root ( ) ) . unwrap ( ) ;
747- let mut cfg = t ! ( repo. config( ) ) ;
748- t ! ( cfg. set_str( "user.email" , "foo@bar.com" ) ) ;
749- t ! ( cfg. set_str( "user.name" , "Foo Bar" ) ) ;
750- drop ( cfg) ;
751- git:: add ( & repo) ;
752- git:: commit ( & repo) ;
753737 File :: create ( & p. root ( ) . join ( "src/lib.rs" ) )
754738 . unwrap ( )
755739 . write_all ( "pub fn bar() {}" . to_string ( ) . as_bytes ( ) )
@@ -776,33 +760,17 @@ commit the changes to these files:
776760
777761#[ cargo_test]
778762fn does_not_warn_about_clean_working_directory ( ) {
779- let p = project ( ) . file ( "src/lib.rs" , "pub fn foo() {}" ) . build ( ) ;
780-
781- let repo = git2:: Repository :: init ( & p. root ( ) ) . unwrap ( ) ;
782- let mut cfg = t ! ( repo. config( ) ) ;
783- t ! ( cfg. set_str( "user.email" , "foo@bar.com" ) ) ;
784- t ! ( cfg. set_str( "user.name" , "Foo Bar" ) ) ;
785- drop ( cfg) ;
786- git:: add ( & repo) ;
787- git:: commit ( & repo) ;
788-
763+ let p = git:: new ( "foo" , |p| p. file ( "src/lib.rs" , "pub fn foo() {}" ) ) ;
789764 p. cargo ( "fix" ) . run ( ) ;
790765}
791766
792767#[ cargo_test]
793768fn does_not_warn_about_dirty_ignored_files ( ) {
794- let p = project ( )
795- . file ( "src/lib.rs" , "pub fn foo() {}" )
796- . file ( ".gitignore" , "bar\n " )
797- . build ( ) ;
769+ let p = git :: new ( "foo" , |p| {
770+ p . file ( "src/lib.rs" , "pub fn foo() {}" )
771+ . file ( ".gitignore" , "bar\n " )
772+ } ) ;
798773
799- let repo = git2:: Repository :: init ( & p. root ( ) ) . unwrap ( ) ;
800- let mut cfg = t ! ( repo. config( ) ) ;
801- t ! ( cfg. set_str( "user.email" , "foo@bar.com" ) ) ;
802- t ! ( cfg. set_str( "user.name" , "Foo Bar" ) ) ;
803- drop ( cfg) ;
804- git:: add ( & repo) ;
805- git:: commit ( & repo) ;
806774 File :: create ( p. root ( ) . join ( "bar" ) ) . unwrap ( ) ;
807775
808776 p. cargo ( "fix" ) . run ( ) ;
@@ -1267,8 +1235,7 @@ fn fix_in_existing_repo_weird_ignore() {
12671235 . file ( "src/lib.rs" , "" )
12681236 . file ( ".gitignore" , "foo\n inner\n " )
12691237 . file ( "inner/file" , "" )
1270- } )
1271- . unwrap ( ) ;
1238+ } ) ;
12721239
12731240 p. cargo ( "fix" ) . run ( ) ;
12741241 // This is questionable about whether it is the right behavior. It should
0 commit comments