Skip to content

Commit

Permalink
fix(publish): show dirty files on dirty check failure (#24541)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret committed Jul 12, 2024
1 parent 2627f6b commit 7ef58ae
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
26 changes: 19 additions & 7 deletions cli/tools/registry/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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.");
}

Expand Down Expand Up @@ -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())
Expand All @@ -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
Expand All @@ -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)]
Expand Down
12 changes: 10 additions & 2 deletions tests/integration/publish_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7ef58ae

Please sign in to comment.