When cargo install --git
checks out a commit, also set the branch and tag refs
#15467
Labels
A-git
Area: anything dealing with git
C-feature-request
Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Command-install
S-needs-team-input
Status: Needs input from team on whether/how to proceed.
Problem
Overview
cargo install --git
does not retrieve tags or branch info.My command is:
cargo install --git https://github.com/tessus/mvt-cargo.git --branch xyz
So, cargo install fetched the correct branch but renamed it to master and did not fetch any tags either. 🤔
P.S.: Please note that this example is a bit exaggerated. In most cases the most recent tag should match the info in
Cargo.toml
. I only used it to even more underscore the issue I am seeing.Details
cargo install
manual checkout and cargo build/install
$ git clone -b xyz https://github.com/tessus/mvt-cargo.git $ cd mvt-cargo $ cargo build --release $ ./target/release/mvt-cargo Version: 0.1.1-0123b0f4 (xyz)
Investigation
A
cargo install --git https://github.com/tessus/mvt-cargo.git --branch xyz
creates a somewhat messed-up git directory in.cargo/git/checkouts/
. e.g.repo-7f25bc5356a562d5
. I call it messed-up because part of the info is missing (tags) and incorrect (branch).The binary is then compiled from within this directory. However, in this directory there are no tags from the
https://github.com/tessus/mvt-cargo.git
repository, nor is the branch name correct.This is why my
build.rs
cannot determine a tag nor the correct branch.In the
repo-7f25bc5356a562d5
dir, the following happens:However, it should show the following (which is also shown when I run these commands in the directory cloned with
git clone -b xyz https://github.com/tessus/mvt-cargo.git
)Problem
As you can see, the output is different depending on how the binary was built.
It is currently impossible to use a
build.rs
script that generates correct information about the git repo, when usingcargo install --git ....
Workaround
cargo install --path ./path/to/repo
orcargo build
(from within the repo)Proposed Solution
Feature request
Preserve tags and branch info, when using
cargo install --git ....
Notes
I am not sure, whether the current behavior is a bug or not. If it is, please let me know and I create a bug report instead.
Otherwise, let's keep this feature request as is.
Link to minimal viable test code: https://github.com/tessus/mvt-cargo/tree/xyz
The text was updated successfully, but these errors were encountered: