Skip to content

Commit

Permalink
Remove --offline empty index error.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Dec 3, 2019
1 parent 626f0f4 commit 1437976
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
12 changes: 0 additions & 12 deletions src/cargo/sources/registry/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
57 changes: 40 additions & 17 deletions tests/testsuite/offline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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]
Expand Down Expand Up @@ -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();
}

0 comments on commit 1437976

Please sign in to comment.