Skip to content

fix(crates): do not modify Cargo.toml during a dry run - #2550

Open
unknownhackerworld wants to merge 1 commit into
intuit:mainfrom
unknownhackerworld:fix/crates-dry-run-version
Open

unknownhackerworld wants to merge 1 commit into
intuit:mainfrom
unknownhackerworld:fix/crates-dry-run-version

Conversation

@unknownhackerworld

Copy link
Copy Markdown

What Changed

The crates plugin no longer writes to Cargo.toml when auto runs with --dry-run.

  • bumpVersion(bumpBy, dryRun = false) in plugins/crates/src/index.ts now returns the computed version before the write when dryRun is true.
  • The version hook passes its dryRun flag through to bumpVersion.

Why

Root cause: in plugins/crates/src/index.ts, the version hook calls bumpVersion(bump) first and only checks dryRun afterwards. bumpVersion always ends with fs.writeFileSync(filePath, contentNew). So the early return in the dry run branch skips cargo build and the commit, but the new version is already written to disk.

Core passes dryRun into the version hook (packages/core/src/auto.ts, version()), and skips checkClean() for dry runs, so this path runs for auto version --dry-run and auto shipit --dry-run. After a dry run with the crates plugin, the working tree has a modified Cargo.toml with the next version. A later real run then starts from a dirty tree, and if the change gets committed by mistake the version is bumped twice.

Fix: keep the version calculation (so the dry run can still log or print the version it would publish) and skip only the file write.

Tradeoffs and alternatives:

  • I added an optional dryRun parameter instead of splitting bumpVersion into separate compute and write functions. bumpVersion is exported, and the optional parameter keeps its current signature and behavior for existing callers.
  • Another option was to compute the version inline in the hook with semver.inc when dryRun is set. That would duplicate the read and parse logic and the "Could not increment" error handling, so I kept it in one place.

Testing

  • Added a unit test that bumpVersion(SEMVER.minor, true) returns 1.3.0 and does not call writeFileSync.
  • Added a hook test that version with dryRun: true does not call writeFileSync or run any command (cargo build, git add, git commit).
  • Both new tests fail on main and pass with this change.
  • npx jest plugins/crates: 16 passed. npx eslint plugins/crates --ext .ts, npx tsc -b plugins/crates and prettier --check on the changed files are clean.
  • I did not run a real cargo publish flow.

Disclosure: this change was found and written with help from an AI coding assistant.

Todo:

  • Add tests
  • Add docs (not needed, no user-facing option changed)

Change Type

Indicate the type of change your pull request is:

  • documentation
  • patch
  • minor
  • major

The version hook called bumpVersion before checking dryRun, and
bumpVersion always wrote the new version to Cargo.toml. So
`auto version --dry-run` and `auto shipit --dry-run` left a modified
Cargo.toml behind. Pass dryRun to bumpVersion and skip the write.
Copilot AI balanced review requested due to automatic review settings October 20, 2026 11:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants