Skip to content

Failed to cargo package --allow-dirty for repo with no commit #14354

Closed
@weihanglo

Description

@weihanglo

Problem

#13960 unconditionally checks VCS status when doing cargo package.
However, a VCS (Git specifically) repository could have no commit history, and then it fails cargo package with such an error:

cargo +beta package --allow-dirty
warning: manifest has no description, license, license-file, documentation, homepage or repository.
See https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata for more info.
error: revspec 'HEAD' not found; class=Reference (4); code=NotFound (-3)

Steps

  1. cargo new foo
  2. cd foo
  3. cargo package --allow-dirty

Possible Solution(s)

The current .cargo_vcs_info.json format looks like:

{
 "git": {
   "sha1": "aac20b6e7e543e6dd4118b246c77225e3a3a1302",
   "dirty": true
 },
 "path_in_vcs": ""
}

If the HEAD hash cannot be determined, should we instead emit a JSON like

{
 "git": {
   "dirty": true
 },
 "path_in_vcs": ""
}

or just don't generate .cargo_vcs_info.json at all?

Notes

No response

Version

cargo 1.81.0-beta.2 (a2b58c3da 2024-07-16)
release: 1.81.0-beta.2
commit-hash: a2b58c3dad4d554ba01ed6c45c41ff85390560f2
commit-date: 2024-07-16

Metadata

Metadata

Assignees

Labels

A-gitArea: anything dealing with gitC-bugCategory: bugCommand-packageS-triageStatus: This issue is waiting on initial triage.regression-from-stable-to-betaRegression in beta that previously worked in stable.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions