cargo-edit icon indicating copy to clipboard operation
cargo-edit copied to clipboard

`cargo upgrade` fails to get crates version when using sparse registry

Open inflation opened this issue 1 year ago • 11 comments

Since there will be no git repo locally after the change to use sparse registry, we need another way to figure out the latest version available.

inflation avatar Feb 10 '23 09:02 inflation

Does it fail in practice from a user changing their config?

From what I understand it shouldn't but I could be wrong.

As for server side, crates.io will continue to support the git registry, so switching to sparse registry is for performance and for alternative registries that drop git registry support.

Personally, I suspect the path to merging into cargo would be the faster / easier route.

epage avatar Feb 10 '23 13:02 epage

If the user had previously fetched the index, they would be fine. However, the main purpose of sparse registry is to speed up fresh setup, so new users after the change would be clueless because the error message is bad:

Error: reference 'refs/heads/master' not found; class=Reference (4); code=NotFound (-3)

Caused by:
    reference 'refs/heads/master' not found; class=Reference (4); code=NotFound (-3)

From what I heard, cargo is currently on a feature freeze. I'm uncertain if this could make it into cargo before the default change.

inflation avatar Feb 11 '23 02:02 inflation

So this isn't a matter of crates-index not properly handling no registry existing. My guess is the sparse registry and git registry are sharing a path and the git registry needs to handle only the sparse registry being initialized

epage avatar Feb 13 '23 16:02 epage

I've tried to find reproduction steps for this to report this upstream but cannot reproduce this.

I've tried

  • rm -rf ~/.cargo/registry and then initializing the index
  • rm -rf ~/.cargo/registry/index/*/.git and then initializing the index

epage avatar Feb 13 '23 16:02 epage

If you do rm -rf ~/.cargo/registry, then cargo upgrade (cargo-edit-upgrade 0.11.9) then Ctrl+C it a few seconds later, then try it again, you get that error. Incomplete checkout, I guess?

5225225 avatar Mar 04 '23 17:03 5225225

If you do rm -rf ~/.cargo/registry, then cargo upgrade (cargo-edit-upgrade 0.11.9) then Ctrl+C it a few seconds later, then try it again, you get that error. Incomplete checkout, I guess?

I got this too.

ttys3 avatar Mar 22 '23 18:03 ttys3

As a workaround, adding the following to .cargo/config.toml fixes the issue:

# Because cargo-upgrade will fail otherwise
# https://github.com/killercup/cargo-edit/issues/841
[registries.crates-io]
protocol = "git"

https://doc.rust-lang.org/cargo/reference/config.html#registriescrates-ioprotocol

aminya avatar Apr 01 '23 04:04 aminya

Just an fyi sparse becomes the default strategy in 1.70.0, due for release on the 1st of June https://releases.rs/docs/1.70.0/

Thanks all for your work!

0atman avatar Apr 27 '23 10:04 0atman

Until https://github.com/frewsxcv/rust-crates-index/issues/87 is fixed, we will have no progression

stevefan1999-personal avatar May 22 '23 09:05 stevefan1999-personal

That was fixed last week, let's go ahead and upgrade it and see if it works

stevefan1999-personal avatar Jun 24 '23 16:06 stevefan1999-personal

To be clear, I would consider that a workaround (moving off of git) rather than a fix to the problem as using a git index at the same time as a parse index should work

epage avatar Jun 25 '23 01:06 epage