Skip to content

Commit 22adaf9

Browse files
committed
Update test to handle user.* git config missing in submodule.
1 parent 850a9d4 commit 22adaf9

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

tests/testsuite/git.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,19 +2695,16 @@ fn git_fetch_cli_env_clean() {
26952695
#[cargo_test]
26962696
fn dirty_submodule() {
26972697
// `cargo package` warns for dirty file in submodule.
2698-
let git_project = git::new("foo", |project| {
2698+
let (git_project, repo) = git::new_repo("foo", |project| {
26992699
project
27002700
.file("Cargo.toml", &basic_manifest("foo", "0.5.0"))
27012701
// This is necessary because `git::add` is too eager.
27022702
.file(".gitignore", "/target")
2703-
})
2704-
.unwrap();
2703+
});
27052704
let git_project2 = git::new("src", |project| {
27062705
project.no_manifest().file("lib.rs", "pub fn f() {}")
2707-
})
2708-
.unwrap();
2706+
});
27092707

2710-
let repo = git2::Repository::open(&git_project.root()).unwrap();
27112708
let url = path2url(git_project2.root()).to_string();
27122709
git::add_submodule(&repo, &url, Path::new("src"));
27132710

@@ -2757,7 +2754,7 @@ to proceed despite [..]
27572754
git_project.cargo("package --no-verify").run();
27582755

27592756
// Try with a nested submodule.
2760-
let git_project3 = git::new("bar", |project| project.no_manifest().file("mod.rs", "")).unwrap();
2757+
let git_project3 = git::new("bar", |project| project.no_manifest().file("mod.rs", ""));
27612758
let url = path2url(git_project3.root()).to_string();
27622759
git::add_submodule(&sub_repo, &url, Path::new("bar"));
27632760
git_project

tests/testsuite/support/git.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,14 @@ impl Repository {
129129
/// Initialize a new repository at the given path.
130130
pub fn init(path: &Path) -> git2::Repository {
131131
let repo = t!(git2::Repository::init(path));
132+
default_repo_cfg(&repo);
133+
repo
134+
}
135+
136+
fn default_repo_cfg(repo: &git2::Repository) {
132137
let mut cfg = t!(repo.config());
133138
t!(cfg.set_str("user.email", "foo@bar.com"));
134139
t!(cfg.set_str("user.name", "Foo Bar"));
135-
drop(cfg);
136-
repo
137140
}
138141

139142
/// Create a new git repository with a project.
@@ -193,6 +196,7 @@ pub fn add_submodule<'a>(
193196
let path = path.to_str().unwrap().replace(r"\", "/");
194197
let mut s = t!(repo.submodule(url, Path::new(&path), false));
195198
let subrepo = t!(s.open());
199+
default_repo_cfg(&subrepo);
196200
t!(subrepo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*"));
197201
let mut origin = t!(subrepo.find_remote("origin"));
198202
t!(origin.fetch(&[], None, None));

0 commit comments

Comments
 (0)