Skip to content

Commit

Permalink
feat: don't generate .cargo_vcs_info.json if git repro has no commit
Browse files Browse the repository at this point in the history
  • Loading branch information
linyihai committed Aug 7, 2024
1 parent d465dd7 commit bb89188
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 19 deletions.
10 changes: 6 additions & 4 deletions src/cargo/ops/cargo_package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,10 +744,12 @@ fn check_repo_state(
.and_then(|p| p.to_str())
.unwrap_or("")
.replace("\\", "/");
return Ok(Some(VcsInfo {
git: git(p, src_files, &repo, &opts)?,
path_in_vcs,
}));
let git = git(p, src_files, &repo, &opts)?;
// In the repo has no commit found, don't include the `VcsInfo`
if git.sha1.is_none() {
return Ok(None);
}
return Ok(Some(VcsInfo { git, path_in_vcs }));
}
}
gctx.shell().verbose(|shell| {
Expand Down
17 changes: 2 additions & 15 deletions tests/testsuite/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,21 +1279,8 @@ fn issue_14354_allowing_dirty_bare_commit() {
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.toml", "Cargo.toml.orig", "src/lib.rs"],
&[],
);
}

Expand Down

0 comments on commit bb89188

Please sign in to comment.