diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 27b680952041..894bbcc8a0b2 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -2054,15 +2054,15 @@ pub struct AddArgs { pub raw_sources: bool, /// Specific commit to use when adding from Git. - #[arg(long)] + #[arg(long, group = "git-ref", action = clap::ArgAction::Set)] pub rev: Option, /// Tag to use when adding from git. - #[arg(long)] + #[arg(long, group = "git-ref", action = clap::ArgAction::Set)] pub tag: Option, /// Branch to use when adding from git. - #[arg(long)] + #[arg(long, group = "git-ref", action = clap::ArgAction::Set)] pub branch: Option, /// Extras to activate for the dependency; may be provided more than once. diff --git a/crates/uv/tests/edit.rs b/crates/uv/tests/edit.rs index 0c40c8f9d05a..adcf7207f14c 100644 --- a/crates/uv/tests/edit.rs +++ b/crates/uv/tests/edit.rs @@ -2033,3 +2033,71 @@ fn add_frozen() -> Result<()> { Ok(()) } + +#[test] +fn add_reject_multiple_git_ref_flags() { + let context = TestContext::new("3.12"); + + // --tag and --branch + uv_snapshot!(context + .add(&[]) + .arg("foo") + .arg("--tag") + .arg("0.0.1") + .arg("--branch") + .arg("test"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: the argument '--tag ' cannot be used with '--branch ' + + Usage: uv add --cache-dir [CACHE_DIR] --tag --exclude-newer ... + + For more information, try '--help'. + "### + ); + + // --tag and --rev + uv_snapshot!(context + .add(&[]) + .arg("foo") + .arg("--tag") + .arg("0.0.1") + .arg("--rev") + .arg("326b943"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: the argument '--tag ' cannot be used with '--rev ' + + Usage: uv add --cache-dir [CACHE_DIR] --tag --exclude-newer ... + + For more information, try '--help'. + "### + ); + + // --tag and --tag + uv_snapshot!(context + .add(&[]) + .arg("foo") + .arg("--tag") + .arg("0.0.1") + .arg("--tag") + .arg("0.0.2"), @r###" + success: false + exit_code: 2 + ----- stdout ----- + + ----- stderr ----- + error: the argument '--tag ' cannot be used multiple times + + Usage: uv add [OPTIONS] ... + + For more information, try '--help'. + "### + ); +}