Skip to content

Commit 1437976

Browse files
committed
Remove --offline empty index error.
1 parent 626f0f4 commit 1437976

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

src/cargo/sources/registry/remote.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,6 @@ impl<'cfg> RegistryData for RemoteRegistry<'cfg> {
184184

185185
fn update_index(&mut self) -> CargoResult<()> {
186186
if self.config.offline() {
187-
if self.repo()?.is_empty()? {
188-
// An empty repository is guaranteed to fail, since hitting
189-
// this path means we need at least one crate. This is an
190-
// attempt to provide a better error message other than "no
191-
// matching package named …".
192-
failure::bail!(
193-
"unable to fetch {} in offline mode\n\
194-
Try running without the offline flag, or try running \
195-
`cargo fetch` within your project directory before going offline.",
196-
self.source_id
197-
);
198-
}
199187
return Ok(());
200188
}
201189
if self.config.cli_unstable().no_index_update {

tests/testsuite/offline.rs

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ fn cargo_compile_with_downloaded_dependency_with_offline() {
144144

145145
#[cargo_test]
146146
fn cargo_compile_offline_not_try_update() {
147+
// When --offline needs to download the registry, provide a reasonable
148+
// error hint to run without --offline.
147149
let p = project()
148150
.at("bar")
149151
.file(
@@ -160,28 +162,23 @@ fn cargo_compile_offline_not_try_update() {
160162
.file("src/lib.rs", "")
161163
.build();
162164

165+
let msg = "\
166+
[ERROR] no matching package named `not_cached_dep` found
167+
location searched: registry `https://github.com/rust-lang/crates.io-index`
168+
required by package `bar v0.1.0 ([..]/bar)`
169+
As a reminder, you're using offline mode (--offline) which can sometimes cause \
170+
surprising resolution failures, if this error is too confusing you may wish to \
171+
retry without the offline flag.
172+
";
173+
163174
p.cargo("build --offline")
164175
.with_status(101)
165-
.with_stderr(
166-
"\
167-
[ERROR] failed to load source for a dependency on `not_cached_dep`
168-
169-
Caused by:
170-
Unable to update registry `https://github.com/rust-lang/crates.io-index`
171-
172-
Caused by:
173-
unable to fetch registry `https://github.com/rust-lang/crates.io-index` in offline mode
174-
Try running without the offline flag, or try running `cargo fetch` within your \
175-
project directory before going offline.
176-
",
177-
)
176+
.with_stderr(msg)
178177
.run();
179178

179+
// While we're here, also check the config works.
180180
p.change_file(".cargo/config", "net.offline = true");
181-
p.cargo("build")
182-
.with_status(101)
183-
.with_stderr_contains("[..]Unable to update registry[..]")
184-
.run();
181+
p.cargo("build").with_status(101).with_stderr(msg).run();
185182
}
186183

187184
#[cargo_test]
@@ -536,3 +533,29 @@ retry without the offline flag.
536533
")
537534
.run();
538535
}
536+
537+
#[cargo_test]
538+
fn offline_with_all_patched() {
539+
// Offline works if everything is patched.
540+
let p = project()
541+
.file(
542+
"Cargo.toml",
543+
r#"
544+
[package]
545+
name = "foo"
546+
version = "0.1.0"
547+
548+
[dependencies]
549+
dep = "1.0"
550+
551+
[patch.crates-io]
552+
dep = {path = "dep"}
553+
"#,
554+
)
555+
.file("src/lib.rs", "pub fn f() { dep::foo(); }")
556+
.file("dep/Cargo.toml", &basic_manifest("dep", "1.0.0"))
557+
.file("dep/src/lib.rs", "pub fn foo() {}")
558+
.build();
559+
560+
p.cargo("check --offline").run();
561+
}

0 commit comments

Comments
 (0)