Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Having a [patch] section when publishing is not an error #6535

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions src/cargo/ops/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
}
}

if !pkg.manifest().patch().is_empty() {
failure::bail!("published crates cannot contain [patch] sections");
}

let (mut registry, reg_id) = registry(
opts.config,
opts.token.clone(),
Expand Down
1 change: 0 additions & 1 deletion src/doc/man/cargo-publish.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ registry. The default registry is https://crates.io. This performs the
following steps:

. Performs a few checks, including:
- No `[patch]` sections are allowed in the manifest.
- Checks the `package.publish` key in the manifest for restrictions on which
registries you are allowed to publish to.
. Create a `.crate` file by following the steps in man:cargo-package[1].
Expand Down
60 changes: 57 additions & 3 deletions tests/testsuite/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -930,17 +930,71 @@ fn publish_with_patch() {
bar = { path = "bar" }
"#,
)
.file("src/main.rs", "extern crate bar; fn main() {}")
.file(
"src/main.rs",
"extern crate bar;
fn main() {
bar::newfunc();
}",
)
.file("bar/Cargo.toml", &basic_manifest("bar", "1.0.0"))
.file("bar/src/lib.rs", "")
.file("bar/src/lib.rs", "pub fn newfunc() {}")
.build();

// Check that it works with the patched crate.
p.cargo("build").run();

// Check that verify fails with patched crate which has new functionality.
p.cargo("publish --index")
.arg(registry_url().to_string())
.with_stderr_contains("[..]newfunc[..]")
.with_status(101)
.with_stderr_contains("[ERROR] published crates cannot contain [patch] sections")
.run();

// Remove the usage of new functionality and try again.
p.change_file("src/main.rs", "extern crate bar; pub fn main() {}");

p.cargo("publish --index")
.arg(registry_url().to_string())
.run();

// Note, use of `registry` in the deps here is an artifact that this
// publishes to a fake, local registry that is pretending to be crates.io.
// Normal publishes would set it to null.
publish::validate_upload(
r#"
{
"authors": [],
"badges": {},
"categories": [],
"deps": [
{
"default_features": true,
"features": [],
"kind": "normal",
"name": "bar",
"optional": false,
"registry": "https://github.com/rust-lang/crates.io-index",
"target": null,
"version_req": "^1.0"
}
],
"description": "foo",
"documentation": null,
"features": {},
"homepage": null,
"keywords": [],
"license": "MIT",
"license_file": null,
"links": null,
"name": "foo",
"readme": null,
"readme_file": null,
"repository": null,
"vers": "0.0.1"
}
"#,
"foo-0.0.1.crate",
&["Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
);
}