Translate '\' to '/' for submodule names

Apparently git submodules are checked in as '/' not '\' so if a '\' leaks
through it'll end up not being found!

Closes #1299
This commit is contained in:
Alex Crichton 2015-02-15 20:23:09 -08:00
parent 98e48728c9
commit 1e0b04a03e
2 changed files with 8 additions and 3 deletions

View file

@ -162,7 +162,10 @@ impl<'a, 'b> PathSource<'a, 'b> {
let rel = try!(rel.to_str().chain_error(|| {
human(format!("invalid utf-8 filename: {}", rel.display()))
}));
let submodule = try!(repo.find_submodule(rel));
// Git submodules are currently only named through `/` path
// separators, explicitly not `\` which windows uses. Who knew?
let rel = rel.replace(r"\", "/");
let submodule = try!(repo.find_submodule(&rel));
let repo = match submodule.open() {
Ok(repo) => repo,
Err(..) => continue,

View file

@ -51,7 +51,8 @@ fn add(repo: &git2::Repository) {
fn add_submodule<'a>(repo: &'a git2::Repository, url: &str,
path: &Path) -> git2::Submodule<'a> {
let mut s = repo.submodule(url, path, false).unwrap();
let path = path.to_str().unwrap().replace(r"\", "/");
let mut s = repo.submodule(url, Path::new(&path), false).unwrap();
let subrepo = s.open().unwrap();
let mut origin = subrepo.find_remote("origin").unwrap();
origin.add_fetch("refs/heads/*:refs/heads/*").unwrap();
@ -1658,12 +1659,13 @@ test!(dont_require_submodules_are_checked_out {
"#)
.file("build.rs", "fn main() {}")
.file("src/lib.rs", "")
.file("a/foo", "")
}).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, &Path::new("submodule"));
add_submodule(&repo, &url, &Path::new("a/submodule"));
commit(&repo);
git2::Repository::init(&project.root()).unwrap();