mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
fix: cargo package
failed on bare commit git repo
This commit is contained in:
parent
a562387d2b
commit
ab4ab66c60
@ -87,7 +87,8 @@ struct VcsInfo {
|
||||
|
||||
#[derive(Serialize)]
|
||||
struct GitVcsInfo {
|
||||
sha1: String,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
sha1: Option<String>,
|
||||
/// Indicate whether or not the Git worktree is dirty.
|
||||
#[serde(skip_serializing_if = "std::ops::Not::not")]
|
||||
dirty: bool,
|
||||
@ -799,9 +800,12 @@ fn check_repo_state(
|
||||
.collect();
|
||||
let dirty = !dirty_src_files.is_empty();
|
||||
if !dirty || opts.allow_dirty {
|
||||
if repo.is_empty()? {
|
||||
return Ok(GitVcsInfo { sha1: None, dirty });
|
||||
}
|
||||
let rev_obj = repo.revparse_single("HEAD")?;
|
||||
Ok(GitVcsInfo {
|
||||
sha1: rev_obj.id().to_string(),
|
||||
sha1: Some(rev_obj.id().to_string()),
|
||||
dirty,
|
||||
})
|
||||
} else {
|
||||
|
@ -1273,13 +1273,28 @@ fn issue_14354_allowing_dirty_bare_commit() {
|
||||
)
|
||||
.file("src/lib.rs", "");
|
||||
|
||||
p.cargo("package --allow-dirty")
|
||||
.with_status(101)
|
||||
.with_stderr_data(str![[r#"
|
||||
[ERROR] revspec 'HEAD' not found; class=Reference (4); code=NotFound (-3)
|
||||
p.cargo("package --allow-dirty").run();
|
||||
|
||||
"#]])
|
||||
.run();
|
||||
let f = File::open(&p.root().join("target/package/foo-0.1.0.crate")).unwrap();
|
||||
validate_crate_contents(
|
||||
f,
|
||||
"foo-0.1.0.crate",
|
||||
&[
|
||||
".cargo_vcs_info.json",
|
||||
"Cargo.toml",
|
||||
"Cargo.toml.orig",
|
||||
"src/lib.rs",
|
||||
],
|
||||
&[(
|
||||
".cargo_vcs_info.json",
|
||||
r#"{
|
||||
"git": {
|
||||
"dirty": true
|
||||
},
|
||||
"path_in_vcs": ""
|
||||
}"#,
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[cargo_test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user