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