Skip to content

Commit 7ef58ae

Browse files
committed
fix(publish): show dirty files on dirty check failure (#24541)
1 parent 2627f6b commit 7ef58ae

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

cli/tools/registry/mod.rs

+19-7
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,13 @@ pub async fn publish(
143143
.ok()
144144
.is_none()
145145
&& !publish_flags.allow_dirty
146-
&& check_if_git_repo_dirty(cli_options.initial_cwd()).await
147146
{
148-
bail!("Aborting due to uncommitted changes. Check in source code or run with --allow-dirty");
147+
if let Some(dirty_text) =
148+
check_if_git_repo_dirty(cli_options.initial_cwd()).await
149+
{
150+
log::error!("\nUncommitted changes:\n\n{}\n", dirty_text);
151+
bail!("Aborting due to uncommitted changes. Check in source code or run with --allow-dirty");
152+
}
149153
}
150154

151155
if publish_flags.dry_run {
@@ -306,7 +310,10 @@ impl PublishPreparer {
306310
} else if std::env::var("DENO_INTERNAL_FAST_CHECK_OVERWRITE").as_deref()
307311
== Ok("1")
308312
{
309-
if check_if_git_repo_dirty(self.cli_options.initial_cwd()).await {
313+
if check_if_git_repo_dirty(self.cli_options.initial_cwd())
314+
.await
315+
.is_some()
316+
{
310317
bail!("When using DENO_INTERNAL_FAST_CHECK_OVERWRITE, the git repo must be in a clean state.");
311318
}
312319

@@ -1130,10 +1137,10 @@ fn verify_version_manifest(
11301137
Ok(())
11311138
}
11321139

1133-
async fn check_if_git_repo_dirty(cwd: &Path) -> bool {
1140+
async fn check_if_git_repo_dirty(cwd: &Path) -> Option<String> {
11341141
let bin_name = if cfg!(windows) { "git.exe" } else { "git" };
11351142

1136-
// Check if git exists
1143+
// Check if git exists
11371144
let git_exists = Command::new(bin_name)
11381145
.arg("--version")
11391146
.stderr(Stdio::null())
@@ -1143,7 +1150,7 @@ async fn check_if_git_repo_dirty(cwd: &Path) -> bool {
11431150
.map_or(false, |status| status.success());
11441151

11451152
if !git_exists {
1146-
return false; // Git is not installed
1153+
return None; // Git is not installed
11471154
}
11481155

11491156
// Check if there are uncommitted changes
@@ -1155,7 +1162,12 @@ async fn check_if_git_repo_dirty(cwd: &Path) -> bool {
11551162
.expect("Failed to execute command");
11561163

11571164
let output_str = String::from_utf8_lossy(&output.stdout);
1158-
!output_str.trim().is_empty()
1165+
let text = output_str.trim();
1166+
if text.is_empty() {
1167+
None
1168+
} else {
1169+
Some(text.to_string())
1170+
}
11591171
}
11601172

11611173
#[allow(clippy::print_stderr)]

tests/integration/publish_tests.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,16 @@ fn allow_dirty() {
413413
.arg("sadfasdf")
414414
.run();
415415
output.assert_exit_code(1);
416-
let output = output.combined_output();
417-
assert_contains!(output, "Aborting due to uncommitted changes. Check in source code or run with --allow-dirty");
416+
output.assert_matches_text(r#"Check [WILDLINE]
417+
Checking for slow types in the public API...
418+
419+
Uncommitted changes:
420+
421+
?? deno.json
422+
?? main.ts
423+
424+
error: Aborting due to uncommitted changes. Check in source code or run with --allow-dirty
425+
"#);
418426

419427
let output = context
420428
.new_command()

0 commit comments

Comments
 (0)