Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo git dependencies do not auto-track latest commit on branch #8555

Closed
hudson-ayers opened this issue Jul 28, 2020 · 4 comments · Fixed by #8561
Closed

Cargo git dependencies do not auto-track latest commit on branch #8555

hudson-ayers opened this issue Jul 28, 2020 · 4 comments · Fixed by #8561
Labels
A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug

Comments

@hudson-ayers
Copy link

Problem

When specifying a dependency using a git repository and a branch, Cargo does not update to track the latest version of that branch when new commits are added, even after a cargo clean. This seems inconsistent with the docs, which state:

Since we haven’t specified any other information, Cargo assumes that we intend to use the latest commit on the master branch to build our package. You can combine the git key with the rev, tag, or branch keys to specify something else. Here's an example of specifying that you want to use the latest commit on a branch named next

I tested this with the following example:

[dependencies]
haybale = {git = "https://github.com/PLSysSec/haybale", branch="32-bit-targets"}

After additional commits were added to this branch, Cargo did not use them, and continued to use the version of the dependency from when I first chose this branch. Even switching to a different branch and then back did not work, I was forced to specify the exact revision instead.

Steps

  1. Add a git-based dependency and specify a specific branch
  2. cargo b your project that uses that dependency
  3. Add commits to the git repo of that dependency, on the specified branch
  4. cargo clean && cargo b
  5. Observe that the latest version is not used

Possible Solution(s)

I think it is fine to leave the behavior as is, but the documentation should be corrected to acknowledge this behavior. Alternatively, cargo could be made to actually check for new commits.

Notes

Output of cargo version: cargo 1.40.0 (bc8e4c8 2019-11-22)

(my apologies if this has been fixed since last november)

OS: Ubuntu 20.04

@hudson-ayers hudson-ayers added the C-bug Category: bug label Jul 28, 2020
@ehuss
Copy link
Contributor

ehuss commented Jul 28, 2020

Yea, the behavior is intentional. One of the fundamental aspects of Cargo is that it has a Cargo.lock file which locks the dependencies to a specific version. With the lock file in place, Cargo will not automatically fetch a new version. You will need to run cargo update to tell it to update the locked version.

Updating that section of the docs seems reasonable to emphasize that once it is locked it will not be updated automatically.

@ehuss ehuss added the A-documenting-cargo-itself Area: Cargo's documentation label Jul 28, 2020
@icorbrey
Copy link

I can work on this

@AlexandreCassagne
Copy link

AlexandreCassagne commented Jul 1, 2024

How does one unlock the Git dependencies? (for example, a command telling cargo to fetch the latest version matching branch)

@weihanglo
Copy link
Member

@AlexandreCassagne The above comments and linked issues should have the answer. cargo update helps you with that. See this doc as well. This issue was closed 4 years ago. Please consider opening a new issue instead of leaving a comment here, if it seems to have some bugs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documenting-cargo-itself Area: Cargo's documentation C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants