Skip to content

Commit

Permalink
feat: yank handling v prefixed semver
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperC286 committed Mar 4, 2025
1 parent 46a8331 commit e851db7
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
16 changes: 14 additions & 2 deletions src/bin/cargo/commands/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,26 @@ fn resolve_crate<'k>(
}

match version {
None => Ok((Some(name), embedded_version)),
None => {
if embedded_version.starts_with('v') {
Ok((Some(name), &embedded_version[1..]))
} else {
Ok((Some(name), embedded_version))
}
}
Some(_) => {
anyhow::bail!("cannot specify both `@{embedded_version}` and `--version`");
}
}
}
None => match version {
Some(version) => Ok((krate, version)),
Some(version) => {
if version.starts_with('v') {
Ok((krate, &version[1..]))
} else {
Ok((krate, version))
}
}
None => {
anyhow::bail!("`--version` is required");
}
Expand Down
20 changes: 14 additions & 6 deletions tests/testsuite/yank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,19 @@ fn explicit_version_prefixing_v() {
.build();

p.cargo("yank --version v0.0.1")
.replace_crates_io(registry.index_url())
.run();

p.cargo("yank --undo --version v0.0.1")
.replace_crates_io(registry.index_url())
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[YANK] foo@v0.0.1
[ERROR] failed to yank from the registry at [ROOTURL]/api
Unyank foo@0.0.1
[ERROR] failed to undo a yank from the registry at [ROOTURL]/api
Caused by:
[37] Could not read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/foo/v0.0.1/yank)
EOF while parsing a value at line 1 column 0
"#]])
.run();
Expand Down Expand Up @@ -185,15 +189,19 @@ fn inline_version_prefixing_v() {
.build();

p.cargo("yank [email protected]")
.replace_crates_io(registry.index_url())
.run();

p.cargo("yank --undo [email protected]")
.replace_crates_io(registry.index_url())
.with_status(101)
.with_stderr_data(str![[r#"
[UPDATING] crates.io index
[YANK] foo@v0.0.1
[ERROR] failed to yank from the registry at [ROOTURL]/api
Unyank foo@0.0.1
[ERROR] failed to undo a yank from the registry at [ROOTURL]/api
Caused by:
[37] Could not read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/foo/v0.0.1/yank)
EOF while parsing a value at line 1 column 0
"#]])
.run();
Expand Down

0 comments on commit e851db7

Please sign in to comment.