Skip to content

Commit

Permalink
Add git-ref group for uv add
Browse files Browse the repository at this point in the history
This allows us to reject specifying more than one git-ref at the CLI level.
  • Loading branch information
eth3lbert committed Jul 27, 2024
1 parent 561625e commit 2572de7
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 3 deletions.
6 changes: 3 additions & 3 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

/// Tag to use when adding from git.
#[arg(long)]
#[arg(long, group = "git-ref", action = clap::ArgAction::Set)]
pub tag: Option<String>,

/// Branch to use when adding from git.
#[arg(long)]
#[arg(long, group = "git-ref", action = clap::ArgAction::Set)]
pub branch: Option<String>,

/// Extras to activate for the dependency; may be provided more than once.
Expand Down
68 changes: 68 additions & 0 deletions crates/uv/tests/edit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 --brach

Check warning on line 2041 in crates/uv/tests/edit.rs

View workflow job for this annotation

GitHub Actions / typos

"brach" should be "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 <TAG>' cannot be used with '--branch <BRANCH>'
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <REQUIREMENTS>...
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 <TAG>' cannot be used with '--rev <REV>'
Usage: uv add --cache-dir [CACHE_DIR] --tag <TAG> --exclude-newer <EXCLUDE_NEWER> <REQUIREMENTS>...
For more information, try '--help'.
"###
);

// --tag and --add
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 <TAG>' cannot be used multiple times
Usage: uv add [OPTIONS] <REQUIREMENTS>...
For more information, try '--help'.
"###
);
}

0 comments on commit 2572de7

Please sign in to comment.