-
Notifications
You must be signed in to change notification settings - Fork 160
Description
Issue
When running cargo upgrade for a project that uses dependencies passed as Git repositories (git+...), the command may fail to update these dependencies due to using the --offline mode for Cargo.
This was observed on a fresh install (when running the command in a GitHub workflow).
Tested with v0.13.4.
Cause
I don't fully understand the cause. My understanding, which may just as well be incorrect, is that using the offline mode for updating Git dependencies (possibly here in the code) relies on some local index being already populated, but this is not always the case. If running in a CI workflow with a fresh rustup installation for example, that index may not be populated. Running cargo update before cargo upgrade -p <package> fixes the issue.
Reproducer
Sorry, I haven't gone as far as reproducing a minimal Cargo.toml, here's an example based on a project I'm working on.
I'm considering a project with a dependency located in a GitHub repo, for example a fork of the ahash crate:
$ cat Cargo.lock
[...]
[[package]]
name = "ahash"
version = "0.8.10"
source = "git+https://github.com/githedgehog/aHash?branch=pr%2Fdaniel-noland%2Fbump-zero-copy#b0b2198d18b30c3683618dd9e9f6a0766648f9a9"
[...]I'm not sure how Cargo's index works, and how to “empty” it. So in order to work from a fresh setup I'm running a new container.
I install git and cargo, I clone the repo, and I try to update the ahash package, in --offline mode:
$ docker run --rm -it ubuntu:24.04
root@5d16f982a0ae:/# apt update
root@5d16f982a0ae:/# apt install --yes git rustup
root@5d16f982a0ae:/# rustup default stable
root@5d16f982a0ae:/# git clone https://github.com/githedgehog/dataplane.git --depth 1 --revision f845e5f951711917260da18e31047955b30e7d40
root@5d16f982a0ae:/# cd dataplane/
root@5d16f982a0ae:/dataplane# cargo update --offline ahash
error: Unable to update https://github.com/githedgehog/aHash?branch=pr%2Fdaniel-noland%2Fbump-zero-copy
Caused by:
can't checkout from 'https://github.com/githedgehog/aHash': you are in the offline mode (--offline)To run the wrapping command cargo upgrade, add:
root@5d16f982a0ae:/dataplane# apt install --yes gcc
root@5d16f982a0ae:/dataplane# cargo install cargo-edit
root@5d16f982a0ae:/dataplane# cargo upgrade -p log
Checking virtual workspace's dependencies
Checking dataplane's dependencies
Checking dataplane-cli's dependencies
name old req compatible latest new req
==== ======= ========== ====== =======
log ^0.4.25 0.4.27 0.4.27 ^0.4.27
Checking dataplane-dpdk's dependencies
Checking dataplane-dpdk-sys's dependencies
Checking dataplane-dpdk-sysroot-helper's dependencies
Checking dataplane-errno's dependencies
Checking dataplane-id's dependencies
Checking dataplane-interface-manager's dependencies
Checking dataplane-mgmt's dependencies
Checking dataplane-net's dependencies
Checking dataplane-pipeline's dependencies
Checking dataplane-rekon's dependencies
Checking dataplane-routing's dependencies
Checking dataplane-vpc-manager's dependencies
Upgrading git dependencies
error: Unable to update https://github.com/githedgehog/aHash?branch=pr%2Fdaniel-noland%2Fbump-zero-copy
Caused by:
failed to lookup reference in preexisting repository, and can't check for updates in offline mode (--offline)
Caused by:
failed to find branch `pr/daniel-noland/bump-zero-copy`
Caused by:
cannot locate remote-tracking branch 'origin/pr/daniel-noland/bump-zero-copy'; class=Reference (4); code=NotFound (-3)
Error: recursive dependency update failedIf I run cargo update, it seems to update the local index, and then the subsequent --offline command works fine:
root@5d16f982a0ae:/dataplane# cargo update
root@5d16f982a0ae:/dataplane# git restore .
root@5d16f982a0ae:/dataplane# cargo update --offline ahash
Locking 0 packages to latest Rust 1.87.0 compatible versions
note: pass `--verbose` to see 2 unchanged dependencies behind latest