Skip to content

Commit 7e89966

Browse files
committed
Auto merge of #10306 - eholk:git-default-branch, r=alexcrichton
Fix new::git_default_branch with different default The test `new::git_default_branch` would fail if the current user had already configured a different default branch. This patch changes the test to first write a `.gitconfig` file with the default branch set to master. This puts us in a state where we still have the old default, and then the subsequent change to the config file will make sure that config changes are still respected.
2 parents 95bb3c9 + 1683cd5 commit 7e89966

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

tests/testsuite/new.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,23 @@ use cargo_test_support::paths;
55
use std::env;
66
use std::fs::{self, File};
77

8-
fn create_empty_gitconfig() {
8+
fn create_default_gitconfig() {
99
// This helps on Windows where libgit2 is very aggressive in attempting to
1010
// find a git config file.
1111
let gitconfig = paths::home().join(".gitconfig");
1212
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();
1325
}
1426

1527
#[cargo_test]
@@ -471,7 +483,8 @@ or change the name in Cargo.toml with:
471483
#[cargo_test]
472484
fn git_default_branch() {
473485
// Check for init.defaultBranch support.
474-
create_empty_gitconfig();
486+
create_default_gitconfig();
487+
475488
cargo_process("new foo").run();
476489
let repo = git2::Repository::open(paths::root().join("foo")).unwrap();
477490
let head = repo.find_reference("HEAD").unwrap();

0 commit comments

Comments
 (0)