Cargo allows using a pinned git hash that doesn't match the specified branch
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 15.5k
- Forks
- 3k
- Avg merge
- 23h 30m
- Merged PRs (30d)
- 51
Description
Problem
If Cargo.toml has a { git = "...", branch = "master" } hash and Cargo.lock points to a specific commit, Cargo should enforce that the commit is somewhere in the history of master. Instead it will silently use the commit.
Steps
cargo initecho 'mime = { git = "https://github.com/hyperium/mime", branch = "0.3.x" }' > Cargo.tomlcargo update -p mime --precise 938484de95445a2af931515d2b7252612c575da7cargo check
Note that https://github.com/hyperium/mime/commit/938484de95445a2af931515d2b7252612c575da7 is only on the master branch.
Possible Solution(s)
Give an error if git merge-base --is-ancestor 938484de95445a2af931515d2b7252612c575da7 origin/0.3.x has a non-zero exit code.
Notes
No response
Version
cargo 1.59.0-nightly (fcef61230 2021-12-17)
release: 1.59.0-nightly
commit-hash: fcef61230c3b6213b6b0d233a36ba4ebd1649ec3
commit-date: 2021-12-17
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.80.0-DEV (sys:0.4.51+curl-7.80.0 vendored ssl:OpenSSL/1.1.1l)
os: Pop!_OS 20.04 (focal) [64-bit]
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the mismatch using the listed Cargo.toml, Cargo.lock, and cargo update steps, then trace Cargo's git dependency resolution and branch validation entry points. Done means Cargo rejects a locked commit outside the requested branch while still accepting a commit in that branch's history.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- build-system, cli, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100