Running any cargo add {crate} would fail with:
Command failed due to unhandled error: reference 'refs/remotes/origin/master' not found; class=Reference (4); code=NotFound (-3)
After some debugging i found that the cargo index had its 'refs/remotes/origin' set to HEAD instead of master. I tried rebuilding the index by running rm -rf ~/.cargo/registry/index/github.com-*/ and then cargo add <any dependency>. This updated the index, however now refs/remotes/origin/ still contains HEAD insted of master.
Found the line in that failed in this lib to be: https://github.com/killercup/cargo-edit/blob/034f6efc6c9c86ce07a0ad01cfbb55198397e1ec/src/fetch.rs#L271
Confirmed that running mv HEAD master temporarily fixed the problem.
Thanks for the report. Hmm, this is strange, I can't reproduce the issue. Have you tried removing the index and rebuilding it with cargo check instead of cargo add?
This is what I got after that:
❯ tree ~/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/refs/remotes/origin
~/.cargo/registry/index/github.com-1ecc6299db9ec823/.git/refs/remotes/origin
└── master
Updating the index is done here:
https://github.com/killercup/cargo-edit/blob/034f6efc6c9c86ce07a0ad01cfbb55198397e1ec/src/fetch.rs#L126-L159
Did indeed fail on cargo check as well. Thow I narrowed down the issue. This works as intended on Stable, but not on nightly.
rustup show
Default host: x86_64-unknown-linux-gnu
rustup home: /home/vagrant/.rustup
installed toolchains
--------------------
stable-x86_64-unknown-linux-gnu
nightly-x86_64-unknown-linux-gnu (default)
active toolchain
----------------
nightly-x86_64-unknown-linux-gnu (default)
rustc 1.46.0-nightly (346aec9b0 2020-07-11)
Might be connected to https://github.com/rust-lang/cargo/pull/8364
I'm facing same issue on nightly.
-bash-5.0$ cargo add clap
Command failed due to unhandled error: reference 'refs/remotes/origin/master' not found; class=Reference (4); code=NotFound (-3)
can I revert back cargo-edit to older version as temporary workaround?
@kavirajk no. Temporarly solution is to rename the file in ~/.cargo/registry/index/github.com-*/.git/refs/remotes/origincalled HEAD to master
Have thought about some fixes. One would be to allow cargo add to use any of the origins. Think we always expects this to have 1 file in that directory.
+1, Same problem with OP, hope for the new version