diff --git a/src/cargo/util/toml/mod.rs b/src/cargo/util/toml/mod.rs index a1be7b0aa46..01a288a09d7 100644 --- a/src/cargo/util/toml/mod.rs +++ b/src/cargo/util/toml/mod.rs @@ -2362,21 +2362,17 @@ fn to_dependency_source_id( orig.registry.as_deref(), orig.registry_index.as_ref(), ) { - (Some(_git), _, Some(_registry), _) | (Some(_git), _, _, Some(_registry)) => bail!( - "dependency ({name_in_toml}) specification is ambiguous. \ - Only one of `git` or `registry` is allowed.", - ), - (_, _, Some(_registry), Some(_registry_index)) => bail!( - "dependency ({name_in_toml}) specification is ambiguous. \ - Only one of `registry` or `registry-index` is allowed.", - ), - (Some(_git), Some(_path), None, None) => { + (Some(_git), Some(_path), _, _) => { bail!( "dependency ({name_in_toml}) specification is ambiguous. \ Only one of `git` or `path` is allowed.", ); } - (Some(git), None, None, None) => { + (_, _, Some(_registry), Some(_registry_index)) => bail!( + "dependency ({name_in_toml}) specification is ambiguous. \ + Only one of `registry` or `registry-index` is allowed.", + ), + (Some(git), None, _, _) => { let n_details = [&orig.branch, &orig.tag, &orig.rev] .iter() .filter(|d| d.is_some()) diff --git a/tests/testsuite/alt_registry.rs b/tests/testsuite/alt_registry.rs index 4a96607c85b..4fd9b33271d 100644 --- a/tests/testsuite/alt_registry.rs +++ b/tests/testsuite/alt_registry.rs @@ -4,6 +4,7 @@ use std::fs; use crate::prelude::*; use cargo_test_support::compare::assert_e2e; +use cargo_test_support::git; use cargo_test_support::publish::validate_alt_upload; use cargo_test_support::registry::{self, Package, RegistryBuilder}; use cargo_test_support::str; @@ -227,13 +228,32 @@ fn registry_and_path_dep_works() { } #[cargo_test] -fn registry_incompatible_with_git() { - registry::alt_init(); +fn registry_and_git_dep_works() { + let _reg = RegistryBuilder::new() + .http_api() + .http_index() + .alternative() + .build(); - let p = project() + let bar = git::repo(&paths::root().join("bar")) .file( "Cargo.toml", r#" + [package] + name = "bar" + version = "0.0.1" + edition = "2015" + authors = [] + "#, + ) + .file("src/lib.rs", "") + .build(); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" [package] name = "foo" version = "0.0.1" @@ -241,20 +261,25 @@ fn registry_incompatible_with_git() { edition = "2015" [dependencies.bar] - git = "" + version = "0.0.1" registry = "alternative" + git="{}" "#, + bar.url(), + ), ) .file("src/main.rs", "fn main() {}") .build(); + Package::new("bar", "0.0.1").alternative(true).publish(); + p.cargo("check") - .with_status(101) .with_stderr_data(str![[r#" -[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml` - -Caused by: - dependency (bar) specification is ambiguous. Only one of `git` or `registry` is allowed. +[UPDATING] git repository `[ROOTURL]/bar` +[LOCKING] 1 package to latest compatible version +[CHECKING] bar v0.0.1 ([ROOTURL]/bar#[..]) +[CHECKING] foo v0.0.1 ([ROOT]/foo) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s "#]]) .run(); @@ -648,6 +673,111 @@ fn publish_with_crates_io_dep() { ); } +#[cargo_test] +fn publish_with_git_and_registry_dep() { + let _reg = RegistryBuilder::new() + .http_api() + .http_index() + .alternative() + .build(); + + let bar = git::repo(&paths::root().join("bar")) + .file( + "Cargo.toml", + r#" + [package] + name = "bar" + version = "0.0.1" + edition = "2015" + authors = [] + "#, + ) + .file("src/lib.rs", "") + .build(); + + let p = project() + .file( + "Cargo.toml", + &format!( + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + edition = "2015" + + [dependencies.bar] + version = "0.0.1" + registry = "alternative" + git="{}" + "#, + bar.url(), + ), + ) + .file("src/main.rs", "fn main() {}") + .build(); + + Package::new("bar", "0.0.1").alternative(true).publish(); + + p.cargo("publish --registry alternative") + .with_stderr_data(str![[r#" +[UPDATING] `alternative` index +[PACKAGING] foo v0.0.1 ([ROOT]/foo) +[UPDATING] `alternative` index +[PACKAGED] 4 files, [FILE_SIZE]B ([FILE_SIZE]B compressed) +[VERIFYING] foo v0.0.1 ([ROOT]/foo) +[DOWNLOADING] crates ... +[DOWNLOADED] bar v0.0.1 (registry `alternative`) +[COMPILING] bar v0.0.1 (registry `alternative`) +[COMPILING] foo v0.0.1 ([ROOT]/foo/target/package/foo-0.0.1) +[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s +[UPLOADING] foo v0.0.1 ([ROOT]/foo) +[UPLOADED] foo v0.0.1 to registry `alternative` +[NOTE] waiting for foo v0.0.1 to be available at registry `alternative` +[HELP] you may press ctrl-c to skip waiting; the crate should be available shortly +[PUBLISHED] foo v0.0.1 at registry `alternative` + +"#]]) + .run(); + + validate_alt_upload( + r#"{ + "authors": [], + "badges": {}, + "categories": [], + "deps": [ + { + "default_features": true, + "features": [], + "kind": "normal", + "name": "bar", + "optional": false, + "target": null, + "version_req": "^0.0.1" + } + ], + "description": null, + "documentation": null, + "features": {}, + "homepage": null, + "keywords": [], + "license": null, + "license_file": null, + "links": null, + "name": "foo", + "readme": null, + "readme_file": null, + "repository": null, + "homepage": null, + "documentation": null, + "rust_version": null, + "vers": "0.0.1" + }"#, + "foo-0.0.1.crate", + &["Cargo.lock", "Cargo.toml", "Cargo.toml.orig", "src/main.rs"], + ); +} + #[cargo_test] fn passwords_in_registries_index_url_forbidden() { registry::alt_init(); diff --git a/tests/testsuite/cargo_add/git_registry/mod.rs b/tests/testsuite/cargo_add/git_registry/mod.rs index a1fd50629a5..05b02077e57 100644 --- a/tests/testsuite/cargo_add/git_registry/mod.rs +++ b/tests/testsuite/cargo_add/git_registry/mod.rs @@ -46,7 +46,6 @@ fn case() { ]) .current_dir(cwd) .assert() - .failure() .stdout_eq(str![""]) .stderr_eq(file!["stderr.term.svg"]); diff --git a/tests/testsuite/cargo_add/git_registry/stderr.term.svg b/tests/testsuite/cargo_add/git_registry/stderr.term.svg index 29767537df2..bbfd3d4877e 100644 --- a/tests/testsuite/cargo_add/git_registry/stderr.term.svg +++ b/tests/testsuite/cargo_add/git_registry/stderr.term.svg @@ -1,9 +1,8 @@ - +