You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Add --allow-downgrade option to set-version command #863
This was previously discussed in #782 (somehow I missed it when previously searching or I would have linked to it).
That was mostly closed because there wasn't a use case to justify the exposing the behavior when moving backwards is generally not what should be done.
In my use case this feature is necessary since our CI/CD needs to create dev packages (deb/rpm) for already released versions.
Can you expand on this. Why are you making packages of source code from a newer version than you are releasing but wanting to release with that old version?
We are using monorepo with multiple independently versioned components. Components are released through alphabeta and stable channels with versions somehow derived from git commit. The problem occurs when we decide to release stable version of single component. After stable release each subsequent commit to monorepo causes pipeline failure since new calculated version has pre-release part added (downgrade). From our perspective this downgrade is desirable since such version will not be considered as an update by yum/apt package managers. We could immediately update version to next alpha but such version is meaningless as we do not starting development cycle on this component yet.
Described approach is not ideal but for our usecase is perfectly fine.
We are using cargo-edit as a tool to manage versions of application, not source code and for this reason we sometimes want to intentionally break the semver rules. As pointed out in #782--force options are incredibly usefull. I think this option would make cargo-edit more versatile without sacrificing its main purpose.
I just want to chime in and say that my colleague was just blocked by this. We're having a problem similar to that of @wiktorsikora where we need to internally release some versions that don't follow semantic versioning. We'll find another way to solve our problem of course, but this feature would have been perfect.
We are just hit by the same issue. I think it makes sense to allow downgrades it the user explicitly states this.
A strategy of preventing the user from making mistakes by default is valuable. A strategy of patronizing the user is not. Even in Rust you can go with unsafe.
I guess our use case is similar to the already reported ones. We have a CI, we use set-version and then git diff if the version is aligned with the tag.
I wish there was a --force option. Of course downgrading is not recommended, but you don't know everyone's workflows.
In our case, we cut a release branch and cargo set-version without issue. The problem comes when we have some fixes that need applying to that release, but it is examples and other things that don't warrant even a patch level upgrade. Sure, we should catch those earlier, but here we are.
During these "doc" fixes, we want to cargo set-version in a PR to add build info (eg: current version x.x.x-prABC. So of course, this fails because it is considered a downgrade:
Error: Cannot downgrade from 24.7.0 to 24.7.0-prABC
I guess we'll need to look at cargo ws just to make it work. But I think cargo-edit should make concessions for the variety of workflows its users have, and just perhaps add a warning about the downgrade.
Reacted by Metinu, Lopez Benjamin and StardustGogeta
During these "doc" fixes, we want to cargo set-version in a PR to add build info (eg: current version x.x.x-prABC. So of course, this fails because it is considered a downgrade:
Build information (+ prefixed) and pre-release (- prefixed) are different things. And semver has no concept of "post-release".
Unless there is something I'm missing in this case, the lack of downgrade in this situation seems to be working as intended as its calling out suspect behavior.
Sheesh... it's called "set version", not "bump version" or "increase version" or "upgrade version". It should allow the version to be set to anything that is a valid version number.
Initially, it seems like the perfect tool to use for CI control of versioning, except that it doesn't actually "set" the version, it imposes its own rules on what it allows.
Tools should be simple and not try to double-guess their users. For everyone who thought that cargo-edit might actually be useful, but discovered like I did that it has its own opinionated thoughts on what version you can "set", just use sed on Cargo.toml instead.
Time and time again I come across authors of such programs who think they know best, impose their opinions on what the tools can do, and don't realise that what integrators really need is simple tools that do what they say on the tin. We can create and solve our own problems, but not if the tools constantly add their own complications we have to work around. It's tiresome.
UNIX philosophy: simple tools should do simple things. Let us dig our own holes and dig ourselves out of them, we're not children.
Reacted by Dominic Slee, Razvan-Daniel Mihai, Metinu, Lopez Benjamin, nullstalgia, Andrej Mihajlov, Manuel, StardustGogeta, Khyber Sen, Tastaturtaste and 3 more
I will add that --allow-downgrade would have been useful for me today.
I was just the program locally to see how tauri updates work, and wanted to revert my change.
❯ cargo set-version 1.6.1
Error: Cannot downgrade from 1.6.2 to 1.6.1
The current message reads as if it is not okay to downgrade in Cargo.toml in any circumstance, which is not correct. For example, building a previous version of a program is a valid use case where the version is downgraded. It was quite frustrating for me to have to type the versions back in manually.
A message like this seems nicer for the user:
❯ cargo set-version 1.6.1
Error: Refusing to downgrade from 1.6.2 to 1.6.1 unless `--allow-downgrade` is used.
Downgrading is not a supported CI workflow, for example, crates.io does not support republishing versions, refer to https://doc.rust-lang.org/cargo/reference/publishing.html.
My thoughts:
In this case, set-version seems to be opinionated as a CI workflow tool, rather than a convenient way to set the version
I was blocked today with this also. We use cargo set-version in CI workflows as ways to move versions forward when preparing for releases, and it does a great job of editing all the right files in a large workspace in one swoop. Problem arose when we accidentally used the wrong release candidate version, we used -rc.3.0 instead of -rc.3, but when we run our workflows to change the version to -rc.3, it fails.
The tool presents as a tool for editing cargo files, but it appears to be more opinionated about publishing specifically.
Just came across the same issue while tweaking our CI pipeline.
When a push occurs, we want to publish the crate into a snapshot registry (Artifactory). Like other registries, it's not possible to publish a crate if its version already exists remotely. We tried using the metadata part to suffix the version with +build.XXX but this part is stripped when publishing. The workaround was to suffix with -build.XXX instead. But if our crate is, let's say at version 0.0.1, running cargo set-version 0.1.0-build.1 will unfortunately fail.
This --allow-downgrade / --force flag would have been handy.
Reacted by Dominic Slee, Eir Nym, Harrison Saturley-Hall, Barnaby and StardustGogeta
I wanted to use this to append -pre to CI-built prerelease artifact version numbers to avoid needing to commit just a -pre beforehand.
I second David's comment, the command is named set-version with --bump being an optional argument, this breaks a lot of user expectations/the principle of least surprise.
Disappointing that sed is winning out over a purpose-built tool. 😕
Initially, it seems like the perfect tool to use for CI control of versioning, except that it doesn't actually "set" the version, it imposes its own rules on what it allows.
This built-in inability to downgrade just bit us again today - a change to the way our CI locks work resulted in pipelines breaking everywhere because of this needless restriction.
Normally, our CI clears the workspace so that cargo set-version is just changing 0.0.0 to something else, so it always works, but in a special case involving submodules (don't ask), the CI system reuses the clone, so there's already a version number set by a previous build.
The lock change resulted in some pipelines running in reverse order, which means that a downgrade was attempted in some cases, which of course failed:
Error: Cannot downgrade from 0.2.10430+rc.589d2617 to 0.2.10429+rc.589d2617
Obviously, it's not great that CI isn't working from a clean slate, but these third-party CI systems are full of optimisations (e.g. skipping clones, reusing checkouts, etc) so it wasn't obvious to us until things broke.
I propose that most many people are using cargo set-version in a CI/automated script environment. I don't have data to back this up, but if this is true, then this arbitrary restriction, with no option to bypass, is silly and short-sighted, because there's no good reason why this should be blocked here.
Reacted by Dominic Slee, Craig Tiu, Jens Reimann and Leo Borai
During these "doc" fixes, we want to cargo set-version in a PR to add build info (eg: current version x.x.x-prABC. So of course, this fails because it is considered a downgrade:
Build information (+ prefixed) and pre-release (- prefixed) are different things. And semver has no concept of "post-release".
Unless there is something I'm missing in this case, the lack of downgrade in this situation seems to be working as intended as its calling out suspect behavior.
We use x.y.z-beta or x.y.z-dev to mark development/beta versions of our app. Since bump does not preserve the suffix, we have to patch it up manually after bump when updating version of our develop branch before the release. But we can't because of artificial limitation where going from 1.2.3 to 1.2.3-beta is considered a downgrade. Please remove this limitation since it renders set-version useless.
As a workaround the one can use toml-cli and cargo-get instead:
# this strips -suffix
cargo set-version --bump minor
# get bumped version
VERSION=$(cargo get workspace.package.version)# add suffix back
BETA_VERSION="$VERSION-beta"# cargo set-version doesn't allow downgrades, patch toml directly
toml set Cargo.toml workspace.package.version "$BETA_VERSION"> Cargo-patched.toml
mv Cargo-patched.toml Cargo.toml
Activity
epage commentedon Jul 14, 2023
This was previously discussed in #782 (somehow I missed it when previously searching or I would have linked to it).
That was mostly closed because there wasn't a use case to justify the exposing the behavior when moving backwards is generally not what should be done.
Can you expand on this. Why are you making packages of source code from a newer version than you are releasing but wanting to release with that old version?
wiktorsikora commentedon Jul 29, 2023
We are using monorepo with multiple independently versioned components. Components are released through
alphabetaandstablechannels with versions somehow derived from git commit. The problem occurs when we decide to release stable version of single component. After stable release each subsequent commit to monorepo causes pipeline failure since new calculated version has pre-release part added (downgrade). From our perspective this downgrade is desirable since such version will not be considered as an update by yum/apt package managers. We could immediately update version to nextalphabut such version is meaningless as we do not starting development cycle on this component yet.Described approach is not ideal but for our usecase is perfectly fine.
We are using cargo-edit as a tool to manage versions of application, not source code and for this reason we sometimes want to intentionally break the semver rules. As pointed out in #782
--forceoptions are incredibly usefull. I think this option would makecargo-editmore versatile without sacrificing its main purpose.skogseth commentedon Nov 15, 2023
I just want to chime in and say that my colleague was just blocked by this. We're having a problem similar to that of @wiktorsikora where we need to internally release some versions that don't follow semantic versioning. We'll find another way to solve our problem of course, but this feature would have been perfect.
ctron commentedon May 28, 2024
We are just hit by the same issue. I think it makes sense to allow downgrades it the user explicitly states this.
A strategy of preventing the user from making mistakes by default is valuable. A strategy of patronizing the user is not. Even in Rust you can go with
unsafe.I guess our use case is similar to the already reported ones. We have a CI, we use
set-versionand thengit diffif the version is aligned with the tag.ctron commentedon May 28, 2024
Just for people running into the same issue, looking for a solution.
Install
cargo-workspaces: https://github.com/pksunkara/cargo-workspaces?tab=readme-ov-file#installationYou can then run the following command to set any version for a workspace, ignoring changes, not creating a git commit/tag.
NickLarsenNZ commentedon Jul 25, 2024
I wish there was a --force option. Of course downgrading is not recommended, but you don't know everyone's workflows.
In our case, we cut a release branch and
cargo set-versionwithout issue. The problem comes when we have some fixes that need applying to that release, but it is examples and other things that don't warrant even a patch level upgrade. Sure, we should catch those earlier, but here we are.During these "doc" fixes, we want to
cargo set-versionin a PR to add build info (eg: current versionx.x.x-prABC. So of course, this fails because it is considered a downgrade:I guess we'll need to look at
cargo wsjust to make it work. But I thinkcargo-editshould make concessions for the variety of workflows its users have, and just perhaps add a warning about the downgrade.epage commentedon Jul 25, 2024
Build information (
+prefixed) and pre-release (-prefixed) are different things. And semver has no concept of "post-release".Unless there is something I'm missing in this case, the lack of downgrade in this situation seems to be working as intended as its calling out suspect behavior.
DavidAntliff commentedon Jul 29, 2024
Sheesh... it's called "set version", not "bump version" or "increase version" or "upgrade version". It should allow the version to be set to anything that is a valid version number.
Initially, it seems like the perfect tool to use for CI control of versioning, except that it doesn't actually "set" the version, it imposes its own rules on what it allows.
Tools should be simple and not try to double-guess their users. For everyone who thought that cargo-edit might actually be useful, but discovered like I did that it has its own opinionated thoughts on what version you can "set", just use
sedonCargo.tomlinstead.Time and time again I come across authors of such programs who think they know best, impose their opinions on what the tools can do, and don't realise that what integrators really need is simple tools that do what they say on the tin. We can create and solve our own problems, but not if the tools constantly add their own complications we have to work around. It's tiresome.
UNIX philosophy: simple tools should do simple things. Let us dig our own holes and dig ourselves out of them, we're not children.
domsleee commentedon Sep 10, 2024
I will add that
--allow-downgradewould have been useful for me today.I was just the program locally to see how tauri updates work, and wanted to revert my change.
The current message reads as if it is not okay to downgrade in
Cargo.tomlin any circumstance, which is not correct. For example, building a previous version of a program is a valid use case where the version is downgraded. It was quite frustrating for me to have to type the versions back in manually.A message like this seems nicer for the user:
My thoughts:
set-versionseems to be opinionated as a CI workflow tool, rather than a convenient way to set the versionleighmcculloch commentedon Oct 24, 2024
I was blocked today with this also. We use cargo set-version in CI workflows as ways to move versions forward when preparing for releases, and it does a great job of editing all the right files in a large workspace in one swoop. Problem arose when we accidentally used the wrong release candidate version, we used
-rc.3.0instead of-rc.3, but when we run our workflows to change the version to-rc.3, it fails.The tool presents as a tool for editing cargo files, but it appears to be more opinionated about publishing specifically.
NickLarsenNZ commentedon Nov 20, 2024
This bites us every release
maximetinu commentedon Jan 17, 2025
--allow-downgradewould have bee very useful for me today as well. The PR was done already, are the any plans to merge it?scotow commentedon Feb 12, 2025
Just came across the same issue while tweaking our CI pipeline.
When a push occurs, we want to publish the crate into a snapshot registry (Artifactory). Like other registries, it's not possible to publish a crate if its version already exists remotely. We tried using the metadata part to suffix the version with
+build.XXXbut this part is stripped when publishing. The workaround was to suffix with-build.XXXinstead. But if our crate is, let's say at version0.0.1, runningcargo set-version 0.1.0-build.1will unfortunately fail.This
--allow-downgrade/--forceflag would have been handy.kdewald commentedon May 29, 2025
Hi, I'm also affected by this. How can we help to get this landed?
nullstalgia commentedon Jul 31, 2025
I wanted to use this to append
-preto CI-built prerelease artifact version numbers to avoid needing to commit just a-prebeforehand.I second David's comment, the command is named
set-versionwith--bumpbeing an optional argument, this breaks a lot of user expectations/the principle of least surprise.Disappointing that
sedis winning out over a purpose-built tool. 😕metasyn commentedon Sep 4, 2025
I also went with sed because of the lack of this feature
DavidAntliff commentedon Dec 2, 2025
This built-in inability to downgrade just bit us again today - a change to the way our CI locks work resulted in pipelines breaking everywhere because of this needless restriction.
Normally, our CI clears the workspace so that
cargo set-versionis just changing 0.0.0 to something else, so it always works, but in a special case involving submodules (don't ask), the CI system reuses the clone, so there's already a version number set by a previous build.The lock change resulted in some pipelines running in reverse order, which means that a downgrade was attempted in some cases, which of course failed:
Obviously, it's not great that CI isn't working from a clean slate, but these third-party CI systems are full of optimisations (e.g. skipping clones, reusing checkouts, etc) so it wasn't obvious to us until things broke.
I propose that
mostmany people are usingcargo set-versionin a CI/automated script environment. I don't have data to back this up, but if this is true, then this arbitrary restriction, with no option to bypass, is silly and short-sighted, because there's no good reason why this should be blocked here.pronebird commentedon Jan 8, 2026
We use
x.y.z-betaorx.y.z-devto mark development/beta versions of our app. Sincebumpdoes not preserve the suffix, we have to patch it up manually after bump when updating version of our develop branch before the release. But we can't because of artificial limitation where going from1.2.3to1.2.3-betais considered a downgrade. Please remove this limitation since it rendersset-versionuseless.As a workaround the one can use
toml-cliandcargo-getinstead: