1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

fix(publish): show dirty files on dirty check failure (#24541)

This commit is contained in:
David Sherret 2024-07-12 15:35:57 -04:00 committed by GitHub
parent 9510a8b7d1
commit 8243c85a47
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 9 deletions

View file

@ -143,9 +143,13 @@ pub async fn publish(
.ok()
.is_none()
&& !publish_flags.allow_dirty
&& check_if_git_repo_dirty(cli_options.initial_cwd()).await
{
bail!("Aborting due to uncommitted changes. Check in source code or run with --allow-dirty");
if let Some(dirty_text) =
check_if_git_repo_dirty(cli_options.initial_cwd()).await
{
log::error!("\nUncommitted changes:\n\n{}\n", dirty_text);
bail!("Aborting due to uncommitted changes. Check in source code or run with --allow-dirty");
}
}
if publish_flags.dry_run {
@ -306,7 +310,10 @@ impl PublishPreparer {
} else if std::env::var("DENO_INTERNAL_FAST_CHECK_OVERWRITE").as_deref()
== Ok("1")
{
if check_if_git_repo_dirty(self.cli_options.initial_cwd()).await {
if check_if_git_repo_dirty(self.cli_options.initial_cwd())
.await
.is_some()
{
bail!("When using DENO_INTERNAL_FAST_CHECK_OVERWRITE, the git repo must be in a clean state.");
}
@ -1130,10 +1137,10 @@ fn verify_version_manifest(
Ok(())
}
async fn check_if_git_repo_dirty(cwd: &Path) -> bool {
async fn check_if_git_repo_dirty(cwd: &Path) -> Option<String> {
let bin_name = if cfg!(windows) { "git.exe" } else { "git" };
// Check if git exists
// Check if git exists
let git_exists = Command::new(bin_name)
.arg("--version")
.stderr(Stdio::null())
@ -1143,7 +1150,7 @@ async fn check_if_git_repo_dirty(cwd: &Path) -> bool {
.map_or(false, |status| status.success());
if !git_exists {
return false; // Git is not installed
return None; // Git is not installed
}
// Check if there are uncommitted changes
@ -1155,7 +1162,12 @@ async fn check_if_git_repo_dirty(cwd: &Path) -> bool {
.expect("Failed to execute command");
let output_str = String::from_utf8_lossy(&output.stdout);
!output_str.trim().is_empty()
let text = output_str.trim();
if text.is_empty() {
None
} else {
Some(text.to_string())
}
}
#[allow(clippy::print_stderr)]

View file

@ -413,8 +413,16 @@ fn allow_dirty() {
.arg("sadfasdf")
.run();
output.assert_exit_code(1);
let output = output.combined_output();
assert_contains!(output, "Aborting due to uncommitted changes. Check in source code or run with --allow-dirty");
output.assert_matches_text(r#"Check [WILDLINE]
Checking for slow types in the public API...
Uncommitted changes:
?? deno.json
?? main.ts
error: Aborting due to uncommitted changes. Check in source code or run with --allow-dirty
"#);
let output = context
.new_command()