summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2024-07-12 15:35:57 -0400
committerGitHub <noreply@github.com>2024-07-12 15:35:57 -0400
commit8243c85a47aff3a1c143294482e22f4c49c1ad7b (patch)
treeab53ca5a2757211df6bc28fc8d74f03fb3481092
parent9510a8b7d19798f08a6513ee303a63247306bc66 (diff)
fix(publish): show dirty files on dirty check failure (#24541)
-rw-r--r--cli/tools/registry/mod.rs26
-rw-r--r--tests/integration/publish_tests.rs12
2 files changed, 29 insertions, 9 deletions
diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs
index 3f59f4e14..8e4d97897 100644
--- a/cli/tools/registry/mod.rs
+++ b/cli/tools/registry/mod.rs
@@ -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)]
diff --git a/tests/integration/publish_tests.rs b/tests/integration/publish_tests.rs
index 26acbd244..1bff2094d 100644
--- a/tests/integration/publish_tests.rs
+++ b/tests/integration/publish_tests.rs
@@ -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()