diff --git a/crates/uv/src/commands/project/version.rs b/crates/uv/src/commands/project/version.rs index ae4e84d18af5b..0d359b7232775 100644 --- a/crates/uv/src/commands/project/version.rs +++ b/crates/uv/src/commands/project/version.rs @@ -294,6 +294,11 @@ pub(crate) async fn project_version( "{old_version} => {new_version} didn't increase the version; when bumping to a pre-release version you also need to increase a release version component, e.g., with `--bump `" )); } + if new_version.is_dev() && !old_version.is_dev() { + return Err(anyhow!( + "{old_version} => {new_version} didn't increase the version; when bumping to a dev version you also need to increase another version component, e.g., with `--bump `" + )); + } return Err(anyhow!( "{old_version} => {new_version} didn't increase the version; provide the exact version to force an update" )); diff --git a/crates/uv/tests/it/version.rs b/crates/uv/tests/it/version.rs index 430a81c8e9ee1..4f6c70d9f73c6 100644 --- a/crates/uv/tests/it/version.rs +++ b/crates/uv/tests/it/version.rs @@ -1524,6 +1524,60 @@ requires-python = ">=3.12" Ok(()) } +// --bump dev but it decreases the version from a stable +#[test] +fn bump_decrease_dev_stable() -> Result<()> { + let context = TestContext::new("3.12"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" +[project] +name = "myproject" +version = "2.3.4" +requires-python = ">=3.12" +"#, + )?; + + uv_snapshot!(context.filters(), context.version() + .arg("--bump").arg("dev"), @" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: 2.3.4 => 2.3.4.dev1 didn't increase the version; when bumping to a dev version you also need to increase another version component, e.g., with `--bump ` + "); + Ok(()) +} + +// --bump dev but it decreases the version from a pre-release +#[test] +fn bump_decrease_dev_prerelease() -> Result<()> { + let context = TestContext::new("3.12"); + + let pyproject_toml = context.temp_dir.child("pyproject.toml"); + pyproject_toml.write_str( + r#" +[project] +name = "myproject" +version = "2.3.4a1" +requires-python = ">=3.12" +"#, + )?; + + uv_snapshot!(context.filters(), context.version() + .arg("--bump").arg("dev"), @" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: 2.3.4a1 => 2.3.4a1.dev1 didn't increase the version; when bumping to a dev version you also need to increase another version component, e.g., with `--bump ` + "); + Ok(()) +} + // --bump major twice #[test] fn bump_double_major() -> Result<()> {