Skip to content

Commit d3f7bb0

Browse files
author
Jethro Beekman
committed
Having a [patch] section when publishing is not an error
1 parent 865cb70 commit d3f7bb0

File tree

3 files changed

+57
-8
lines changed

3 files changed

+57
-8
lines changed

src/cargo/ops/registry.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
6060
}
6161
}
6262

63-
if !pkg.manifest().patch().is_empty() {
64-
failure::bail!("published crates cannot contain [patch] sections");
65-
}
66-
6763
let (mut registry, reg_id) = registry(
6864
opts.config,
6965
opts.token.clone(),

src/doc/man/cargo-publish.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ registry. The default registry is https://crates.io. This performs the
1919
following steps:
2020

2121
. Performs a few checks, including:
22-
- No `[patch]` sections are allowed in the manifest.
2322
- Checks the `package.publish` key in the manifest for restrictions on which
2423
registries you are allowed to publish to.
2524
. Create a `.crate` file by following the steps in man:cargo-package[1].

tests/testsuite/publish.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,17 +930,71 @@ fn publish_with_patch() {
930930
bar = { path = "bar" }
931931
"#,
932932
)
933-
.file("src/main.rs", "extern crate bar; fn main() {}")
933+
.file(
934+
"src/main.rs",
935+
"extern crate bar;
936+
fn main() {
937+
bar::newfunc();
938+
}",
939+
)
934940
.file("bar/Cargo.toml", &basic_manifest("bar", "1.0.0"))
935-
.file("bar/src/lib.rs", "")
941+
.file("bar/src/lib.rs", "pub fn newfunc() {}")
936942
.build();
937943

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

947+
// Check that verify fails with patched crate which has new functionality.
941948
p.cargo("publish --index")
942949
.arg(registry_url().to_string())
950+
.with_stderr_contains("[..]newfunc[..]")
943951
.with_status(101)
944-
.with_stderr_contains("[ERROR] published crates cannot contain [patch] sections")
945952
.run();
953+
954+
// Remove the usage of new functionality and try again.
955+
p.change_file("src/main.rs", "extern crate bar; pub fn main() {}");
956+
957+
p.cargo("publish --index")
958+
.arg(registry_url().to_string())
959+
.run();
960+
961+
// Note, use of `registry` in the deps here is an artifact that this
962+
// publishes to a fake, local registry that is pretending to be crates.io.
963+
// Normal publishes would set it to null.
964+
publish::validate_upload(
965+
r#"
966+
{
967+
"authors": [],
968+
"badges": {},
969+
"categories": [],
970+
"deps": [
971+
{
972+
"default_features": true,
973+
"features": [],
974+
"kind": "normal",
975+
"name": "bar",
976+
"optional": false,
977+
"registry": "https://github.com/rust-lang/crates.io-index",
978+
"target": null,
979+
"version_req": "^1.0"
980+
}
981+
],
982+
"description": "foo",
983+
"documentation": null,
984+
"features": {},
985+
"homepage": null,
986+
"keywords": [],
987+
"license": "MIT",
988+
"license_file": null,
989+
"links": null,
990+
"name": "foo",
991+
"readme": null,
992+
"readme_file": null,
993+
"repository": null,
994+
"vers": "0.0.1"
995+
}
996+
"#,
997+
"foo-0.0.1.crate",
998+
&["Cargo.toml", "Cargo.toml.orig", "src/main.rs"],
999+
);
9461000
}

0 commit comments

Comments
 (0)