From 2d59372e7a605360e084c40c5c14cdc52f7d570b Mon Sep 17 00:00:00 2001 From: Asher Gomez Date: Sat, 23 Mar 2024 06:41:33 +1100 Subject: [PATCH] feat(publish): check for uncommitted files in `deno publish --dry-run` (#22981) Closes #22936 --- cli/tools/registry/mod.rs | 18 ++++++++--------- tests/integration/publish_tests.rs | 31 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/cli/tools/registry/mod.rs b/cli/tools/registry/mod.rs index e323c6c794..b40aeaeb4b 100644 --- a/cli/tools/registry/mod.rs +++ b/cli/tools/registry/mod.rs @@ -988,6 +988,15 @@ pub async fn publish( bail!("No packages to publish"); } + if std::env::var("DENO_TESTING_DISABLE_GIT_CHECK") + .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 publish_flags.dry_run { for (_, package) in prepared_data.package_by_name { log::info!( @@ -1003,15 +1012,6 @@ pub async fn publish( return Ok(()); } - if std::env::var("DENO_TESTING_DISABLE_GIT_CHECK") - .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"); - } - perform_publish( cli_factory.http_client(), prepared_data.publish_order_graph, diff --git a/tests/integration/publish_tests.rs b/tests/integration/publish_tests.rs index f6ee1b371a..a033f5d070 100644 --- a/tests/integration/publish_tests.rs +++ b/tests/integration/publish_tests.rs @@ -708,3 +708,34 @@ fn allow_dirty_not_in_repo() { let output = output.combined_output(); assert_contains!(output, "Successfully published"); } + +#[test] +fn allow_dirty_dry_run() { + let context = publish_context_builder_with_git_checks().build(); + let temp_dir = context.temp_dir().path(); + temp_dir.join("deno.json").write_json(&json!({ + "name": "@foo/bar", + "version": "1.0.0", + "exports": "./main.ts", + })); + + temp_dir.join("main.ts").write(""); + + let cmd = Command::new("git") + .arg("init") + .arg(temp_dir.as_path()) + .output() + .unwrap(); + assert!(cmd.status.success()); + + let output = context + .new_command() + .arg("publish") + .arg("--dry-run") + .arg("--token") + .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"); +}