killercup / cargo-edit

A utility for managing cargo dependencies from the command line.
http://killercup.github.io/cargo-edit/
MIT License
3.06k stars 147 forks source link

Error: The repo at path ... is unusable due to having an invalid HEAD reference #879

Open szabgab opened 10 months ago

szabgab commented 10 months ago

When I run cargo-upgrade upgrade I get:

Error: The repo at path /home/gabor/.cargo/registry/index/github.com-1ecc6299db9ec823 is unusable
due to having an invalid HEAD reference: reference 'refs/heads/main' not found; class=Reference (4);
code=NotFound (-3)

Apparently this was caused by me Ctrl-C-in a previous run of cargo-upgrade upgrade that seemed to have been stuck (not showing anything for more than a minute) After removing that folder and running cargo-upgrade upgrade again (and Ctrl-C-ing again) I get the same error.

dpathakj commented 10 months ago

This happened to me today too. See #869, #841. A workaround is described in #869. I fixed this for myself by:

  1. blowing away my entire Cargo registry (by removing .cargo/registry entirely, but importantly NOT the rest of .cargo) (this might not be the smartest way to get back into a good state, but I didn't really feel like figuring out how to fix my existing .cargo/registry in-place, and I'm not sure it matters much*)
  2. using the method described by @dmartin's comment at https://github.com/killercup/cargo-edit/issues/869#issuecomment-1696223822:
    CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git cargo fetch
    CARGO_REGISTRIES_CRATES_IO_PROTOCOL=git cargo upgrade # <-- you might not need to use the env variable here, since the repo will exist after the last command

* If I'm reading the issues right, I am pretty sure the issue only occurs when you have a cargo install that has only ever used sparse checkouts - so you're probably not deleting any data that would take a long time to re-fetch. The cargo fetch in step 2 will still take a long time. But if the problem is as described in the issues listed above, you wouldn't have had that data locally in the first place.

loynoir commented 6 months ago

Same error.

Error gone, after changing from sparse+https:// to non sparse https://.

Search related problems, found related https://github.com/rust-lang/cargo/issues/12425.

CosminPerRam commented 1 month ago

Also encountered this issue, deleting the .cargo/registry folder worked for me afterwards.