Skip to content

Commit e851db7

Browse files
committed
feat: yank handling v prefixed semver
1 parent 46a8331 commit e851db7

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/bin/cargo/commands/yank.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,26 @@ fn resolve_crate<'k>(
5454
}
5555

5656
match version {
57-
None => Ok((Some(name), embedded_version)),
57+
None => {
58+
if embedded_version.starts_with('v') {
59+
Ok((Some(name), &embedded_version[1..]))
60+
} else {
61+
Ok((Some(name), embedded_version))
62+
}
63+
}
5864
Some(_) => {
5965
anyhow::bail!("cannot specify both `@{embedded_version}` and `--version`");
6066
}
6167
}
6268
}
6369
None => match version {
64-
Some(version) => Ok((krate, version)),
70+
Some(version) => {
71+
if version.starts_with('v') {
72+
Ok((krate, &version[1..]))
73+
} else {
74+
Ok((krate, version))
75+
}
76+
}
6577
None => {
6678
anyhow::bail!("`--version` is required");
6779
}

tests/testsuite/yank.rs

+14-6
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,19 @@ fn explicit_version_prefixing_v() {
7373
.build();
7474

7575
p.cargo("yank --version v0.0.1")
76+
.replace_crates_io(registry.index_url())
77+
.run();
78+
79+
p.cargo("yank --undo --version v0.0.1")
7680
.replace_crates_io(registry.index_url())
7781
.with_status(101)
7882
.with_stderr_data(str![[r#"
7983
[UPDATING] crates.io index
80-
[YANK] foo@v0.0.1
81-
[ERROR] failed to yank from the registry at [ROOTURL]/api
84+
Unyank foo@0.0.1
85+
[ERROR] failed to undo a yank from the registry at [ROOTURL]/api
8286
8387
Caused by:
84-
[37] Could not read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/foo/v0.0.1/yank)
88+
EOF while parsing a value at line 1 column 0
8589
8690
"#]])
8791
.run();
@@ -185,15 +189,19 @@ fn inline_version_prefixing_v() {
185189
.build();
186190

187191
p.cargo("yank [email protected]")
192+
.replace_crates_io(registry.index_url())
193+
.run();
194+
195+
p.cargo("yank --undo [email protected]")
188196
.replace_crates_io(registry.index_url())
189197
.with_status(101)
190198
.with_stderr_data(str![[r#"
191199
[UPDATING] crates.io index
192-
[YANK] foo@v0.0.1
193-
[ERROR] failed to yank from the registry at [ROOTURL]/api
200+
Unyank foo@0.0.1
201+
[ERROR] failed to undo a yank from the registry at [ROOTURL]/api
194202
195203
Caused by:
196-
[37] Could not read a file:// file (Couldn't open file [ROOT]/api/api/v1/crates/foo/v0.0.1/yank)
204+
EOF while parsing a value at line 1 column 0
197205
198206
"#]])
199207
.run();

0 commit comments

Comments
 (0)