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

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

Closed
weihanglo opened this issue Aug 5, 2024 · 4 comments · Fixed by #14359
Closed

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

weihanglo opened this issue Aug 5, 2024 · 4 comments · Fixed by #14359
Assignees
Labels
A-git Area: anything dealing with git C-bug Category: bug Command-package regression-from-stable-to-beta Regression in beta that previously worked in stable. S-triage Status: This issue is waiting on initial triage.

Comments

@weihanglo
Copy link
Member

weihanglo commented Aug 5, 2024

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
@weihanglo weihanglo added C-bug Category: bug A-git Area: anything dealing with git Command-package regression-from-stable-to-beta Regression in beta that previously worked in stable. S-triage Status: This issue is waiting on initial triage. labels Aug 5, 2024
@linyihai
Copy link
Contributor

linyihai commented Aug 6, 2024

@rustbot claim

@weihanglo
Copy link
Member Author

Here are some possible solutions:

  1. Don't include .cargo_vcs_info.json at all
    • This maintains the old behavior without blocking cargo package.
  2. Don't include the git.sha key.
    • The git.dirty is still here to tell it is a dirty Git repo without a commit.
  3. Don't include the entire git object.
    • A Git repository without any commit is kinda useless so stripping it off.
  4. Treat it as a non-Git package.
    • Non-git package is assumed clean and will not include .cargo_vcs_info.json.

Any other solutions?

Mind that this is a bit time-bound as it breaks the stable usage of Cargo.

@epage
Copy link
Contributor

epage commented Aug 8, 2024

Don't include .cargo_vcs_info.json at all

I lean towards this seems the least controversial starting point, especially if this is time bound.

Mind that this is a bit time-bound as it breaks the stable usage of Cargo.

While this is a stable-to-beta regression, I'm assuming the end-user impact is pretty minimal. I can't see it being terribly common (and most likely a mistake) to publish from an empty repo.

@weihanglo
Copy link
Member Author

Agree on least controversial and minimal impact parts. I'll go ahead and merge #14359.

@bors bors closed this as completed in b66cad8 Aug 8, 2024
weihanglo pushed a commit to weihanglo/cargo that referenced this issue Aug 9, 2024
Fix: `cargo package` failed on bare commit git repo.

### What does this PR try to resolve?
Fixes rust-lang#14354

This approach chose to not generate a `.cargo_vcs_info.json` for bare commit git repo.

### How should we test and review this PR?
Compare the test changes before and after the two commits

### Additional information
Turbo87 added a commit to Turbo87/crates.io that referenced this issue Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-git Area: anything dealing with git C-bug Category: bug Command-package regression-from-stable-to-beta Regression in beta that previously worked in stable. S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants