Repository navigation
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
Nice foundation for wt sync. The merge-base-based parent inference with two-tier (true-ancestor / diverged) selection is a reasonable approach, and the integration-reparent path is well-structured. A few findings:
1. print_tree_node produces flat output — the tree drawing is broken.
Both connector and child_prefix special-case prefix.is_empty(), returning "" in that case. But the recursion passes child_prefix as the next call's prefix, so every descendant also sees prefix == "" and never gets a connector. The "└── " / "├── " / "│ " / " " branches are unreachable, which is why codecov flags them as uncovered.
The sync_dry_run_linear_stack.snap snapshot confirms it — the output is:
Dependency tree:
main
pr1
pr2
instead of the intended:
Dependency tree:
main
└── pr1
└── pr2
Easiest fix: handle the root once in print_sync_plan and call print_tree_node only for children with an unconditional connector. See the inline suggestion on src/commands/sync.rs.
2. --all is a no-op in this PR.
SyncArgs::all is declared in src/cli/mod.rs with conflicts_with = "stack", but handle_sync_command derives let all = !args.stack; and never reads args.all. So wt sync --all behaves identically to wt sync. The help text says "overrides config", but config isn't introduced until #2061.
I'd suggest dropping --all from this PR and adding it in #2061 where it actually overrides something — or at least wiring it up so args.all forces all = true even when (eventually) a config default of stack applies. Leaving a user-visible flag whose only effect is being rejected alongside --stack is confusing.
3. codecov/patch is failing at 81%.
Beyond the dead-code lines from the tree bug, the biggest untested surface is the rebase-conflict handling in both branches of handle_sync (lines 474–492 for rebase --onto and 503–521 for the normal rebase) — is_rebasing() / user-facing hints / early return Ok(()) are entirely untested. Given conflict recovery is a core behavior of this command, it's worth adding at least one integration test that forces a conflict and checks the error path. The bail! when the default branch has no worktree (line 153) and the "in-progress rebase" guard (lines 425–430) are also uncovered.
4. Stacked with #2053.
#2053 (same author, same feature) is still open with the monolithic version. If #2059/#2060/#2061 supersede it, closing #2053 would avoid confusion for other reviewers.
Minor:
handle_sync_commandcallsCommandEnv::for_action_branchless()?and binds to_env, thenhandle_syncimmediately callsRepository::current()?again. The_envdoes nothing — removing it avoids a duplicate repo/config load.build_dependency_treeunwrapsrepo.integration_target()to gettarget_ref, then passes it torepo.integration_reason(branch, target_ref), which internally callseffective_integration_target(target)again. Passing&default_branchdirectly achieves the same result.error_messageandhint_messageare used with a fully-qualifiedworktrunk::styling::path while the module-top imports already bring ineprintln,progress_message,success_message,warning_message. Adding them to the import keeps the rebase-error blocks readable.
1f4227c to
173ce6c
Compare
wt sync core rebase engineCore implementation of `wt sync` that detects parent-child relationships between worktree branches and rebases them in topological order. Features: - Automatic dependency tree detection via merge-base analysis - Topological sort for correct rebase ordering - Integration detection (squash-merged branches) with reparenting - Dirty worktree detection to prevent data loss - --dry-run mode to preview planned rebases - --stack flag to sync only the current stack (default: all stacks) Includes 10 integration tests covering linear stacks, deep stacks, mid-stack changes, dirty worktree blocking, and PR merge scenarios.
The root call passed empty prefix, and children of root also received empty prefix, making them all appear as root nodes. Fix by passing an explicit is_root flag so only the actual root prints without connectors.
The --all field was never read (main.rs derives `all` from `!args.stack`), and its help text referenced config that doesn't exist yet. Remove the dead field and its conflicts_with constraint.
Covers the conflict handling branch that shows error and resolution hint when a rebase conflict occurs during sync.
|
Moved to a standalone binary: https://github.com/pablospe/worktrunk-sync — works via the external subcommand dispatch merged in #2054. |
|
Superseded — sync moved to separate repo: https://github.com/pablospe/worktrunk-sync |
Summary
wt synccommand that rebases stacked worktree branches in topological order--stackflag to sync only the current stack and--dry-runfor previewingStack: 1/3 — next: sync-stack-file (stack file persistence), then sync-flags (--fetch/--push/--prune + config)
Test plan