Skip to content

Commit 085c813

Browse files
committed
Merge pull request #1365 from elly/cargo
cargo: allow 'ref' package key for git packages.
2 parents dedfef4 + bbc534b commit 085c813

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/cargo/cargo.rs

+15-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type package = {
3131
uuid: str,
3232
url: str,
3333
method: str,
34+
ref: option::t<str>,
3435
tags: [str]
3536
};
3637

@@ -242,6 +243,11 @@ fn load_one_source_package(&src: source, p: map::hashmap<str, json::json>) {
242243
}
243244
};
244245

246+
let ref = alt p.find("ref") {
247+
some(json::string(_n)) { some(_n) }
248+
_ { none }
249+
};
250+
245251
let tags = [];
246252
alt p.find("tags") {
247253
some(json::list(js)) {
@@ -260,6 +266,7 @@ fn load_one_source_package(&src: source, p: map::hashmap<str, json::json>) {
260266
uuid: uuid,
261267
url: url,
262268
method: method,
269+
ref: ref,
263270
tags: tags
264271
});
265272
log " Loaded package: " + src.name + "/" + name;
@@ -398,8 +405,14 @@ fn install_source(c: cargo, path: str) {
398405
}
399406
}
400407

401-
fn install_git(c: cargo, wd: str, url: str) {
408+
fn install_git(c: cargo, wd: str, url: str, ref: option::t<str>) {
402409
run::run_program("git", ["clone", url, wd]);
410+
if option::is_some::<str>(ref) {
411+
let r = option::get::<str>(ref);
412+
fs::change_dir(wd);
413+
run::run_program("git", ["checkout", r]);
414+
}
415+
403416
install_source(c, wd);
404417
}
405418

@@ -424,7 +437,7 @@ fn install_file(c: cargo, wd: str, path: str) {
424437
fn install_package(c: cargo, wd: str, pkg: package) {
425438
info("Installing with " + pkg.method + " from " + pkg.url + "...");
426439
if pkg.method == "git" {
427-
install_git(c, wd, pkg.url);
440+
install_git(c, wd, pkg.url, pkg.ref);
428441
} else if pkg.method == "http" {
429442
install_curl(c, wd, pkg.url);
430443
} else if pkg.method == "file" {

0 commit comments

Comments
 (0)