From 14379767eeaad02efcb946e9ebcd976b6bfbf358 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Tue, 3 Dec 2019 11:52:10 -0800 Subject: [PATCH] Remove --offline empty index error. --- src/cargo/sources/registry/remote.rs | 12 ------ tests/testsuite/offline.rs | 57 +++++++++++++++++++--------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/cargo/sources/registry/remote.rs b/src/cargo/sources/registry/remote.rs index 7d83b113310..49dd7af2b4a 100644 --- a/src/cargo/sources/registry/remote.rs +++ b/src/cargo/sources/registry/remote.rs @@ -184,18 +184,6 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> { fn update_index(&mut self) -> CargoResult<()> { if self.config.offline() { - if self.repo()?.is_empty()? { - // An empty repository is guaranteed to fail, since hitting - // this path means we need at least one crate. This is an - // attempt to provide a better error message other than "no - // matching package named …". - failure::bail!( - "unable to fetch {} in offline mode\n\ - Try running without the offline flag, or try running \ - `cargo fetch` within your project directory before going offline.", - self.source_id - ); - } return Ok(()); } if self.config.cli_unstable().no_index_update { diff --git a/tests/testsuite/offline.rs b/tests/testsuite/offline.rs index 65d98aa4d09..49e99526e37 100644 --- a/tests/testsuite/offline.rs +++ b/tests/testsuite/offline.rs @@ -144,6 +144,8 @@ fn cargo_compile_with_downloaded_dependency_with_offline() { #[cargo_test] fn cargo_compile_offline_not_try_update() { + // When --offline needs to download the registry, provide a reasonable + // error hint to run without --offline. let p = project() .at("bar") .file( @@ -160,28 +162,23 @@ fn cargo_compile_offline_not_try_update() { .file("src/lib.rs", "") .build(); + let msg = "\ +[ERROR] no matching package named `not_cached_dep` found +location searched: registry `https://github.com/rust-lang/crates.io-index` +required by package `bar v0.1.0 ([..]/bar)` +As a reminder, you're using offline mode (--offline) which can sometimes cause \ +surprising resolution failures, if this error is too confusing you may wish to \ +retry without the offline flag. +"; + p.cargo("build --offline") .with_status(101) - .with_stderr( - "\ -[ERROR] failed to load source for a dependency on `not_cached_dep` - -Caused by: - Unable to update registry `https://github.com/rust-lang/crates.io-index` - -Caused by: - unable to fetch registry `https://github.com/rust-lang/crates.io-index` in offline mode -Try running without the offline flag, or try running `cargo fetch` within your \ -project directory before going offline. -", - ) + .with_stderr(msg) .run(); + // While we're here, also check the config works. p.change_file(".cargo/config", "net.offline = true"); - p.cargo("build") - .with_status(101) - .with_stderr_contains("[..]Unable to update registry[..]") - .run(); + p.cargo("build").with_status(101).with_stderr(msg).run(); } #[cargo_test] @@ -536,3 +533,29 @@ retry without the offline flag. ") .run(); } + +#[cargo_test] +fn offline_with_all_patched() { + // Offline works if everything is patched. + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + dep = "1.0" + + [patch.crates-io] + dep = {path = "dep"} + "#, + ) + .file("src/lib.rs", "pub fn f() { dep::foo(); }") + .file("dep/Cargo.toml", &basic_manifest("dep", "1.0.0")) + .file("dep/src/lib.rs", "pub fn foo() {}") + .build(); + + p.cargo("check --offline").run(); +}