Skip to content

Commit c993a54

Browse files
committed
auto merge of rust-lang#72 : Arcterus/cargo/master, r=alexcrichton
Now Cargo should give a normal error message rather than a task failure when encountering an SSH URL as a dependency.
2 parents c919f2f + 856f370 commit c993a54

File tree

3 files changed

+46
-25
lines changed

3 files changed

+46
-25
lines changed

src/bin/cargo-git-checkout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ extern crate hammer;
1010

1111
use cargo::{execute_main_without_stdin};
1212
use cargo::core::MultiShell;
13-
use cargo::core::source::{Source,SourceId};
13+
use cargo::core::source::{Source, SourceId};
1414
use cargo::sources::git::{GitSource};
1515
use cargo::util::{Config, CliResult, CliError, Require, human};
1616
use url::Url;

src/cargo/util/toml.rs

+17-24
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@ use serialize::Decodable;
22
use std::collections::HashMap;
33
use std::str;
44
use toml;
5-
use url;
65

76
use core::{SourceId, GitKind};
87
use core::manifest::{LibKind, Lib, Profile};
98
use core::{Summary, Manifest, Target, Dependency, PackageId};
10-
use core::source::{Location, Local, Remote};
9+
use core::source::Location;
1110
use util::{CargoResult, Require, human};
1211

1312
pub fn to_manifest(contents: &[u8],
@@ -118,15 +117,6 @@ impl TomlManifest {
118117

119118
let mut deps = Vec::new();
120119

121-
fn to_location(s: &str) -> Location {
122-
if s.starts_with("file:") {
123-
Local(Path::new(s.slice_from(5)))
124-
} else {
125-
// TODO: Don't unwrap here
126-
Remote(url::from_str(s).unwrap())
127-
}
128-
}
129-
130120
// Collect the deps
131121
match self.dependencies {
132122
Some(ref dependencies) => {
@@ -141,19 +131,22 @@ impl TomlManifest {
141131
.or_else(|| details.rev.as_ref().map(|t| t.clone()))
142132
.unwrap_or_else(|| "master".to_str());
143133

144-
let new_source_id = details.git.as_ref().map(|git| {
145-
let kind = GitKind(reference.clone());
146-
let loc = to_location(git.as_slice());
147-
let source_id = SourceId::new(kind, loc);
148-
// TODO: Don't do this for path
149-
sources.push(source_id.clone());
150-
source_id
151-
}).or_else(|| {
152-
details.path.as_ref().map(|path| {
153-
nested_paths.push(Path::new(path.as_slice()));
154-
source_id.clone()
155-
})
156-
}).unwrap_or(SourceId::for_central());
134+
let new_source_id = match details.git {
135+
Some(ref git) => {
136+
let kind = GitKind(reference.clone());
137+
let loc = try!(Location::parse(git.as_slice()));
138+
let source_id = SourceId::new(kind, loc);
139+
// TODO: Don't do this for path
140+
sources.push(source_id.clone());
141+
Some(source_id)
142+
}
143+
None => {
144+
details.path.as_ref().map(|path| {
145+
nested_paths.push(Path::new(path.as_slice()));
146+
source_id.clone()
147+
})
148+
}
149+
}.unwrap_or(SourceId::for_central());
157150

158151
(details.version.clone(), new_source_id)
159152
}

tests/test_cargo_compile_git_deps.rs

+28
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,34 @@ test!(cargo_compile_with_nested_paths {
302302
execs().with_stdout("hello world\n"));
303303
})
304304

305+
test!(cargo_compile_with_short_ssh_git {
306+
let url = "git@github.com:a/dep";
307+
308+
let project = project("project")
309+
.file("Cargo.toml", format!(r#"
310+
[project]
311+
312+
name = "foo"
313+
version = "0.5.0"
314+
authors = ["wycats@example.com"]
315+
316+
[dependencies.dep]
317+
318+
git = "{}"
319+
320+
[[bin]]
321+
322+
name = "foo"
323+
"#, url))
324+
.file("src/foo.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]));
325+
326+
assert_that(project.cargo_process("cargo-build"),
327+
execs()
328+
.with_stdout("")
329+
.with_stderr(format!("Cargo.toml is not a valid manifest\n\n\
330+
invalid url `{}`: `url: Invalid character in scheme.\n", url)));
331+
})
332+
305333
test!(recompilation {
306334
let git_project = git_repo("bar", |project| {
307335
project

0 commit comments

Comments
 (0)