Don't require all submodules are checked out

When probing a repository for files that should be considered as inputs for a
build script we should just skip submodules that haven't been checked out
instead of throwing an error.

Closes #1248
This commit is contained in:
Alex Crichton 2015-01-29 11:41:00 -08:00
parent 453ae9f268
commit 98bd1f7448
2 changed files with 35 additions and 2 deletions

View file

@ -155,7 +155,10 @@ impl<'a, 'b> PathSource<'a, 'b> {
human(format!("invalid utf-8 filename: {}", rel.display()))
}));
let submodule = try!(repo.find_submodule(rel));
let repo = try!(submodule.open());
let repo = match submodule.open() {
Ok(repo) => repo,
Err(..) => continue,
};
let files = try!(self.list_files_git(pkg, repo, filter));
ret.extend(files.into_iter());
} else if (*filter)(&file_path) {

View file

@ -6,7 +6,7 @@ use git2;
use support::{ProjectBuilder, project, execs, main_file};
use support::{cargo_dir, path2url};
use support::{COMPILING, UPDATING, RUNNING};
use support::paths::PathExt;
use support::paths::{self, PathExt};
use hamcrest::{assert_that,existing_file};
use cargo;
use cargo::util::{ProcessError, process};
@ -1651,3 +1651,33 @@ test!(switch_sources {
{compiling} project v0.5.0 ([..])
", updating = UPDATING, compiling = COMPILING).as_slice()));
});
test!(dont_require_submodules_are_checked_out {
let project = project("foo");
let git1 = git_repo("dep1", |p| {
p.file("Cargo.toml", r#"
[project]
name = "foo"
version = "0.5.0"
authors = []
build = "build.rs"
"#)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
}).unwrap();
let git2 = git_repo("dep2", |p| p).unwrap();
let repo = git2::Repository::open(&git1.root()).unwrap();
let url = path2url(git2.root()).to_string();
add_submodule(&repo, url.as_slice(), &Path::new("submodule"));
commit(&repo);
git2::Repository::init(&project.root()).unwrap();
let url = path2url(git1.root()).to_string();
let dst = paths::home().join("foo");
git2::Repository::clone(&url[], &dst).unwrap();
assert_that(git1.process(cargo_dir().join("cargo")).arg("build").arg("-v")
.cwd(dst),
execs().with_status(0));
});