Repository navigation
feat(step promote): add --format text|json flag (parity with rebase/push/etc.) - #3424
Conversation
Mirrors the --format text|json flag that 9 sibling step commands already have (commit, squash, rebase, push, copy-ignored, eval, for-each, prune, relocate). Closes the parity gap from max-sixty#3423. In JSON mode the structured envelope is emitted to stdout and the human-readable success/info messages are suppressed. The mismatch warning stays on stderr in both modes because it is a safety signal, not a status line; consumers can also read `mismatch: true|false` from the JSON envelope to detect the same condition programmatically. JSON shape: - Promoted (canonical): {"outcome":"promoted","target":..,"main_branch":..,"swapped":N,"mismatch":false} - Promoted (mismatch): {"outcome":"promoted","target":..,"main_branch":..,"swapped":N,"mismatch":true} - Already in main: {"outcome":"already_in_main","branch":..} PromoteResult::Promoted grows fields { target, main_branch, swapped, mismatch } so the dispatch site can serialize them. AlreadyInMain was already carrying the branch. handle_promote gains a json_mode: bool parameter to gate the text-mode success messages.
worktrunk-bot
left a comment
There was a problem hiding this comment.
The change itself looks correct and is well-tested: the JSON envelope goes to stdout, human status/warnings stay on stderr, the three new tests cover already_in_main, the mismatch swap, and the restore case, and mismatch: !is_restoring matches exactly the condition under which the safety warning fires. Nice work threading the warning through so it still shows on stderr in JSON mode.
Two notes:
Holding for maintainer review (data-loss surface). Per this repo's review policy, wt step promote sits on the deletion surface — src/commands/step/promote.rs already contains fs::remove_dir_all / fs::remove_file (the staging move/cleanup) and an rm -rf recovery hint, and this PR edits handle_promote directly. That means the bot shouldn't be the one to approve it even though the diff reads as harmless output plumbing that doesn't touch the stage/exchange/distribute logic. Requesting @max-sixty to make the merge call.
Parity claim vs. rebase/push. The title says "parity with rebase/push/etc.", but the implementation actually diverges from those two: handle_rebase and handle_push always emit their success line to stderr even under --format=json, whereas this adds a json_mode param to handle_promote to suppress the "Promoted:" / "Swapped …" lines in JSON mode (matching relocate instead). Both conventions exist in the tree, so this isn't wrong — but if the goal is parity with rebase/push specifically, dropping json_mode and always printing the success line to stderr would make handle_promote structurally identical to them (the JSON on stdout is unaffected either way). Your call; flagging since the stated goal and the code point in slightly different directions.
One inline suggestion below on the regenerated snapshot.
The worktrunk bot review on max-sixty#3424 flagged that the `assertion_line: 53` field in this snapshot: - isn't carried by any other committed snapshot (only 2 of 1120 include it, the other one being an unrelated switch test) - will churn spuriously whenever line numbering in help.rs shifts - asserts nothing Drop it to keep the snapshot stable. `cargo insta test --accept` would produce the same change automatically, but a manual edit is enough here since the field is purely decorative noise. Refs: addresses worktrunk-bot inline review on max-sixty#3424.
please can we make this consistent? @worktrunk-bot please can you do this, and then @fuleinist can revert if they disagree |
Match rebase/push: handle_promote drops the json_mode param and always prints the "Promoted:"/"Swapped" status lines to stderr, regardless of --format. The JSON envelope on stdout is unaffected. Previously JSON mode suppressed the human status line (relocate's convention); rebase/push always emit it, so this makes handle_promote structurally identical to them per the stated parity goal.
|
Done in 3f7a916. Dropped the Also extended @fuleinist — happy to revert if you preferred the |
|
CI is green on 3f7a916 — all required checks pass ( The one red mark, |
|
@worktrunk-bot please fix the windows flake in a new PR |
|
Opened #3427. The panic was the re-run's exact The PR adds a sibling I couldn't pin down why wt self-exits 1 on a correct Windows create (no error path in |
Closes #3423.
Adds
--format text|jsontowt step promote, mirroring the flag already present on 9 sibling step commands (commit, squash, rebase, push, copy-ignored, eval, for-each, prune, relocate).Design
The worktree-bot comment on #3423 flagged a real design fork:
promote's stderr output isn't only a summary —print_promote_announcementalso emits the mismatch warning (Promoting creates mismatched worktree state (shown as ⚑ in wt list)), which is a safety signal rather than a status line.This PR threads a
json_mode: boolintohandle_promoteand:mismatch: true|falseboolean to the JSON envelope so consumers can detect the same condition programmaticallyJSON shape
```json
// Promoted, restoring canonical state
{
"outcome": "promoted",
"target": "feature",
"main_branch": "main",
"swapped": 42,
"mismatch": false
}
// Promoted, creating mismatch
{
"outcome": "promoted",
"target": "develop",
"main_branch": "main",
"swapped": 0,
"mismatch": true
}
// Already in main
{
"outcome": "already_in_main",
"branch": "feature"
}
```
Mirrors the field shapes from
step rebase --format=json(target,outcome) andstep push --format=json(outcome,commits,merge_sha), adding promote-specific fields (main_branch,swapped,mismatch).Implementation
StepCommand::Promotegains aformat: SwitchFormatfield with the same--help-heading and doc-comment pattern asStepCommand::RebasePromoteResult::Promotedgrows fields{ target, main_branch, swapped, mismatch }(was a unit variant);AlreadyInMain(String)was already carrying the branchhandle_promotesignature gainsjson_mode: bool; gates the success messages on!json_modemain.rsdispatch mirrors the rebase pattern:if format == SwitchFormat::Json { println!(serde_json::to_string_pretty(&output)?) }else print the text-mode AlreadyInMain info messagecargo insta test --acceptdocs/content/step.mdandskills/worktrunk/reference/step.mdregenerated bycargo test --test integration test_docs_are_in_syncTests
tests/integration_tests/step_promote.rs:test_promote_already_in_main_json— outcome"already_in_main"test_promote_swap_json— outcome"promoted"withmismatch: true+ verifies mismatch warning still surfaces on stderrtest_promote_restore_json— outcome"promoted"withmismatch: falsestep_promotetests still passhelp::*tests still pass (only thehelp_step_promotesnapshot regenerated for the new--formatflag)Use case
A Claude Code / Codex agent running
wt step promotefrom apre-mergehook wants to confirm success and surface the result back as a structured event. Today requires stderr-grepping for"Promoted:". With this flag the agent consumes one JSON line from stdout and routes the failure path via the existing exit code.Diff size
7 files, +192/-27 lines. Surgical, no new dependencies.
Disclosure
Filed from fuleinist, a recurring GitHub-issue contributor. Not generated by AI; I read
src/cli/step.rs,src/cli/mod.rs,src/main.rs,src/commands/step/promote.rs,src/commands/step/rebase.rs,tests/integration_tests/merge.rs, and the new snapshot directly before drafting.