Skip to content

Commit

Permalink
Update test to handle user.* git config missing in submodule.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Aug 13, 2019
1 parent 850a9d4 commit 22adaf9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
11 changes: 4 additions & 7 deletions tests/testsuite/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2695,19 +2695,16 @@ fn git_fetch_cli_env_clean() {
#[cargo_test]
fn dirty_submodule() {
// `cargo package` warns for dirty file in submodule.
let git_project = git::new("foo", |project| {
let (git_project, repo) = git::new_repo("foo", |project| {
project
.file("Cargo.toml", &basic_manifest("foo", "0.5.0"))
// This is necessary because `git::add` is too eager.
.file(".gitignore", "/target")
})
.unwrap();
});
let git_project2 = git::new("src", |project| {
project.no_manifest().file("lib.rs", "pub fn f() {}")
})
.unwrap();
});

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

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

// Try with a nested submodule.
let git_project3 = git::new("bar", |project| project.no_manifest().file("mod.rs", "")).unwrap();
let git_project3 = git::new("bar", |project| project.no_manifest().file("mod.rs", ""));
let url = path2url(git_project3.root()).to_string();
git::add_submodule(&sub_repo, &url, Path::new("bar"));
git_project
Expand Down
8 changes: 6 additions & 2 deletions tests/testsuite/support/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,14 @@ impl Repository {
/// Initialize a new repository at the given path.
pub fn init(path: &Path) -> git2::Repository {
let repo = t!(git2::Repository::init(path));
default_repo_cfg(&repo);
repo
}

fn default_repo_cfg(repo: &git2::Repository) {
let mut cfg = t!(repo.config());
t!(cfg.set_str("user.email", "foo@bar.com"));
t!(cfg.set_str("user.name", "Foo Bar"));
drop(cfg);
repo
}

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

0 comments on commit 22adaf9

Please sign in to comment.