Skip to content

Commit d743987

Browse files
committed
fix: tweak message and add test for patch
1 parent 1a7720c commit d743987

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

src/cargo/util/toml/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::ffi::OsStr;
44
use std::path::{Path, PathBuf};
55
use std::rc::Rc;
66
use std::str::{self, FromStr};
7+
use tracing_subscriber::fmt::format;
78

89
use crate::core::summary::MissingDependencyError;
910
use crate::AlreadyPrintedError;
@@ -2194,11 +2195,12 @@ fn bail_if_github_pull_request(name_in_toml: &str, url: &Url) -> CargoResult<()>
21942195
}
21952196
let path_components = url.path().split('/').collect::<Vec<_>>();
21962197
if let ["", owner, repo, "pull", pr_number, ..] = path_components[..] {
2198+
let repo_url = format!("https://github.com/{owner}/{repo}.git");
2199+
let rev = format!("refs/pull/{pr_number}/head");
21972200
bail!(
2198-
"dependency ({name_in_toml}) specifies a GitHub pull request link. \
2199-
If you were trying to specify a specific github PR, replace the URL with the git \
2200-
URL (e.g. `git = \"https://github.com/{owner}/{repo}.git\"`) \
2201-
and add `rev = \"refs/pull/{pr_number}/head\"` in the dependency declaration.",
2201+
"dependency ({name_in_toml}) git url {url} is not a repository. \
2202+
The path looks like a pull request. Try replacing the dependency with: \
2203+
`git = \"{repo_url}\" rev = \"{rev}\"` in the dependency declaration.",
22022204
);
22032205
}
22042206
Ok(())

tests/testsuite/bad_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ fn github_pull_request_url() {
21762176
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
21772177
21782178
Caused by:
2179-
dependency (bar) specifies a GitHub pull request link. If you were trying to specify a specific github PR, replace the URL with the git URL (e.g. `git = "https://github.com/foo/bar.git"`) and add `rev = "refs/pull/123/head"` in the dependency declaration.
2179+
dependency (bar) git url https://github.com/foo/bar/pull/123 is not a repository. The path looks like a pull request. Try replacing the dependency with: `git = "https://github.com/foo/bar.git" rev = "refs/pull/123/head"` in the dependency declaration.
21802180
21812181
"#]])
21822182
.run();

tests/testsuite/patch.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,50 @@ fn patch_to_git() {
357357
.run();
358358
}
359359

360+
#[cargo_test]
361+
fn patch_to_git_pull_request() {
362+
let bar = git::repo(&paths::root().join("override"))
363+
.file("Cargo.toml", &basic_manifest("bar", "0.1.0"))
364+
.file("src/lib.rs", "pub fn bar() {}")
365+
.build();
366+
367+
Package::new("bar", "0.1.0").publish();
368+
369+
let p = project()
370+
.file(
371+
"Cargo.toml",
372+
r#"
373+
[package]
374+
name = "foo"
375+
version = "0.0.1"
376+
edition = "2015"
377+
authors = []
378+
379+
[dependencies]
380+
bar = "0.1"
381+
382+
[patch.crates-io]
383+
bar = { git = 'https://github.com/foo/bar/pull/123' }
384+
"#,
385+
)
386+
.file(
387+
"src/lib.rs",
388+
"extern crate bar; pub fn foo() { bar::bar(); }",
389+
)
390+
.build();
391+
392+
p.cargo("check -v")
393+
.with_status(101)
394+
.with_stderr_data(str![[r#"
395+
[ERROR] failed to parse manifest at `[ROOT]/foo/Cargo.toml`
396+
397+
Caused by:
398+
dependency (bar) git url https://github.com/foo/bar/pull/123 is not a repository. The path looks like a pull request. Try replacing the dependency with: `git = "https://github.com/foo/bar.git" rev = "refs/pull/123/head"` in the dependency declaration.
399+
400+
"#]])
401+
.run();
402+
}
403+
360404
#[cargo_test]
361405
fn unused() {
362406
Package::new("bar", "0.1.0").publish();

0 commit comments

Comments
 (0)