@@ -5,11 +5,23 @@ use cargo_test_support::paths;
5
5
use std:: env;
6
6
use std:: fs:: { self , File } ;
7
7
8
- fn create_empty_gitconfig ( ) {
8
+ fn create_default_gitconfig ( ) {
9
9
// This helps on Windows where libgit2 is very aggressive in attempting to
10
10
// find a git config file.
11
11
let gitconfig = paths:: home ( ) . join ( ".gitconfig" ) ;
12
12
File :: create ( gitconfig) . unwrap ( ) ;
13
+
14
+ // If we're running this under a user account that has a different default branch set up
15
+ // then tests that assume the default branch is master will fail. We set the default branch
16
+ // to master explicitly so that tests that rely on this behavior still pass.
17
+ fs:: write (
18
+ paths:: home ( ) . join ( ".gitconfig" ) ,
19
+ r#"
20
+ [init]
21
+ defaultBranch = master
22
+ "# ,
23
+ )
24
+ . unwrap ( ) ;
13
25
}
14
26
15
27
#[ cargo_test]
@@ -471,19 +483,7 @@ or change the name in Cargo.toml with:
471
483
#[ cargo_test]
472
484
fn git_default_branch ( ) {
473
485
// Check for init.defaultBranch support.
474
- create_empty_gitconfig ( ) ;
475
-
476
- // If we're running this under a user account that has a different default branch set up
477
- // this test will fail. We avoid that setting the defaultBranch and then ensuring that
478
- // the changed setting is respected.
479
- fs:: write (
480
- paths:: home ( ) . join ( ".gitconfig" ) ,
481
- r#"
482
- [init]
483
- defaultBranch = master
484
- "# ,
485
- )
486
- . unwrap ( ) ;
486
+ create_default_gitconfig ( ) ;
487
487
488
488
cargo_process ( "new foo" ) . run ( ) ;
489
489
let repo = git2:: Repository :: open ( paths:: root ( ) . join ( "foo" ) ) . unwrap ( ) ;
0 commit comments