Repository navigation
Conversation
worktrunk-bot
left a comment
There was a problem hiding this comment.
A few observations on the stack-file persistence layer:
1. New persistent file not in the FAQ inventory. docs/content/faq.md lists everything Worktrunk creates under .git/wt/ (cache, logs, trash). This PR adds .git/wt/stack as a new durable file but doesn't update that table. The project CLAUDE.md data-safety section explicitly calls out that surface area: "New code that changes this surface area should be reviewed against these sections."
2. --dry-run has a side effect. In handle_sync, the dry-run branch calls write_stack_file before returning, and does so before the dirty/rebase safety checks run. Users generally expect --dry-run to be read-only — a dry-run on a stale stack file will silently rewrite .git/wt/stack (and create_dir_all the wt dir). Worth either confining the write to the non-dry-run path, or documenting the side effect explicitly in the --dry-run help and the module docstring.
3. SyncPlan is a dead wrapper. The struct has a single tree: DependencyTree field and the caller immediately unwraps it (let plan = build_dependency_tree(&repo)?; let tree = plan.tree;). CLAUDE.md: "Don't create helpers, utilities, or abstractions for one-time operations." Returning DependencyTree directly is simpler and matches the pre-PR signature.
4. No unit tests for the stack-file parser/formatter. parse_stack_file and format_stack_file aren't trivial — they claim git-machete compatibility, mix tab/space indent handling, handle comments, strip annotations, and implicitly omit the root. The integration tests only exercise the happy-path round-trip. Direct unit tests for:
- round-trip (
format_stack_file→parse_stack_filepreserves structure) - tab vs space indentation
- comments and blank lines
- annotations after branch name
- sibling branches at the same indent level
would pin down the contract and catch regressions if someone tries to switch indent styles later. The existing #[cfg(test)] mod tests block only covers topological_order / stack_containing.
5. Minor: docstring example for parse_stack_file shows main at the top (lines 144–150), but format_stack_file never writes the root branch — so the file worktrunk actually produces looks different from the example in the doc. Either update the example to match what format_stack_node writes, or make format_stack_node include the root.
One inline suggestion below for the .unwrap() on line 170 (CLAUDE.md: "Never .expect() or .unwrap() in functions returning Result").
|
Stack-file logic (
Rebase conflict paths (
The module docstring says "Stops on first conflict; user resolves and re-runs" but there's no integration test exercising the conflict branch. A test that sets up a conflicting change and asserts the hint/exit is the highest-value gap. Control-flow edges in
The parse/format edge cases line up with review point #4 (unit tests for the parser/formatter). The reparenting cycle guard is also untested — adding a direct unit test for |
a7899bb to
40324f2
Compare
|
Addressed the review feedback:
Also replaced |
|
Confirmed — 60b5cbe adds ( |
a0dbe79 to
e428f5d
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI is already red on lint for the latest push — both cargo fmt and cargo clippy fail. The clippy error is also a CLAUDE.md rule: no .unwrap() in functions returning Result. Inline suggestion below for the clippy hit; cargo fmt needs to be re-run on src/commands/sync.rs and src/main.rs as well.
One other observation on the most recent commits:
rebased_branches is now dead code. 8d51f4d switched --push from pushing rebased_branches to pushing all upstream branches in branches_to_sync, but the let mut rebased_branches: Vec<String> = Vec::new(); (line 696) and the rebased_branches.push(...) (line 781) were left behind. The vec is populated but never read.
|
All three Sync-specific (need
Likely rebase fallout (not sync-specific):
Spot-checking After fixing the clippy/fmt issues from the review, |
e428f5d to
b301b09
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
CI is red on four issues — the first two were flagged in earlier reviews and have new context.
1. Clippy unnecessary_unwrap still failing (src/commands/sync.rs:746). This is the same finding from the previous review that wasn't addressed. 9d49693b fixed the parse_stack_file unwrap but not this one. Inline suggestion below.
2. pre-commit fmt also wants to reflow save_fork_points and the reformatted progress_message block — run cargo fmt after applying the clippy fix.
3. Skill reference FAQ out of sync with docs. docs/content/faq.md adds both .git/wt/stack and .git/wt/stack-forkpoints, but skills/worktrunk/reference/faq.md only has .git/wt/stack. test_command_pages_and_skill_files_are_in_sync is panicking on this. Fix:
cargo test --test integration test_command_pages_and_skill_files_are_in_sync…then commit the updated skill file. (The 7047ec7b sync commit predates 812bfdd5 which introduced stack-forkpoints.)
4. config_show / list_config snapshot drift. The snapshots committed in aee9c2b1 still don't match test output — multiple failures in test_deprecated_* and test_list_config_*. Looks like main has moved again since the snapshot restore. cargo insta test --accept after rebasing.
Scope concern — overlap with #2061. The incremental commits pushed since the previous review include 47b4c8cd feat: add --fetch, --push, --prune flags and [sync] config section, which is the exact scope of #2061 (sync-flags, part 3/3). Comparing the branch tips, sync-stack-file is 9 commits ahead of sync-flags and 0 commits behind — this PR now contains everything #2061 was meant to add. Either close #2061 as superseded, or revert the flags/config commits here and keep them in #2061. As-is, merging #2060 leaves #2061 with nothing to do.
Minor (not blocking):
rebased_branches(line 696) is still populated but never read — same finding as the previous review, still unaddressed after933cb871switched--pushto iteratebranches_to_syncdirectly. Can be deleted.load_fork_points+save_fork_pointsroundtrip preserves old entries verbatim (line 691 and line 1064-ish). When a worktree is pruned or a branch is renamed, its entry stays in.git/wt/stack-forkpointsforever. Consider pruning entries for branches not in the current tree at save time.
1f75899 to
a65f691
Compare
Core 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.
Persists the dependency tree to `.git/wt/stack` (git-machete compatible format) on every sync. When present, the stack file: - Provides explicit parent tracking instead of merge-base inference - Enables Phase 2 integration detection against non-default branches (e.g., PR2 squash-merged into PR1, not just into main) - Supports parent chain walking for cascading merge reparenting Includes 5 integration tests: stack file creation, mid-stack fix with stack file, non-default branch merges, mid-stack parent merges, and cascading merges.
Optional phases for `wt sync`: - `--fetch` runs `git fetch --prune` before syncing - `--push` force-pushes rebased branches with `--force-with-lease` (skips branches without an upstream) - `--prune` removes integrated worktrees (worktree + local branch + remote branch), without --force to preserve untracked files All phases default to off. Configurable via `[sync]` config section: ```toml [sync] fetch = true push = true prune = false all = true ``` CLI flags (`--no-fetch`, `--no-push`, `--no-prune`) override config. Includes 4 integration tests: fetch, push, push-skips-deleted-remote, and prune.
…alize SyncConfig is a table section, not a scalar, so it needs to be in the table_lines match arm to generate correct TOML for the deserialization test.
Use .ok().flatten() instead of ? for upstream() calls in the push and prune loops. One branch with an upstream error should not abort the entire phase. Also collapse nested if block to satisfy clippy, and refactor prune to use execute_removal for consistent worktree cleanup.
Replace open-coded if-else chains with flag_pair() calls for all sync flag pairs (fetch, push, prune, all/stack), matching the pattern used by wt merge.
…pairs Change all sync flag pairs to use overrides_with, matching the convention used by wt merge. This allows shell alias composition where the last flag wins, instead of erroring on conflicting flags.
These snapshots legitimately include the [sync] config section added by the sync-flags feature. They were incorrectly reverted to main.
These snapshots capture `wt list` output (not config TOML), so they don't need the [sync] section. The corrupted versions had wrong paths (../../../../), dirty markers (⚑), and timeout placeholders (⋯) from being captured in a wrong CWD during a previous rebase.
Functions returning Result must not use .unwrap(). Use a let-else pattern to safely skip lines where split_whitespace yields nothing.
Users expect --dry-run to be read-only. The write_stack_file call was incorrectly placed in the dry-run branch, causing a side effect.
SyncPlan had a single field that the caller immediately unwrapped. Return DependencyTree directly from build_dependency_tree instead.
Document the stack file created by wt sync in the "What files does Worktrunk create?" section.
Use `git status --porcelain -uno` instead of `is_dirty()` which includes untracked files. Untracked files are safe during rebase and should not block `wt sync`.
Previously --push only pushed branches that were rebased in the current run. Now it pushes all branches in the stack that have an upstream, making `wt sync --push` a complete "sync and push" workflow.
Always use `git rebase --onto <parent> <fork-point> <branch>` instead of `git rebase <parent>`. The fork-point (parent's tip SHA at last sync) is stored in `.git/wt/stack-forkpoints` and updated after each sync. This fixes the "rebase of a rebase" problem: when a parent branch is rewritten (rebased, amended, force-pushed), `git rebase parent` tries to replay the parent's old commits because the merge-base shifts to an older common ancestor. With `--onto`, only the branch's own commits are replayed, correctly handling parent rewrites.
Respects pushRemote, remote.pushDefault, and branch.<name>.remote config so push and prune work with fork-based workflows.
Replace is_some()/unwrap() with if-let pattern, and remove rebased_branches which became dead code after --push was changed to push all upstream branches.
Covers parse_stack_file edge cases (comments, blank lines, annotations, tab/space indentation, siblings, empty input, with/without root), format/parse round-trips, stack_containing edge cases, and fork-points serialization.
- Detached HEAD with --stack reports "no branch" error (covers L622-623) - Fix test_sync_creates_stack_file: dry-run no longer writes stack file - Update push snapshots to include remote name in output
a65f691 to
5afd351
Compare
worktrunk-bot
left a comment
There was a problem hiding this comment.
The incremental changes since the previous review are on the light side — cargo fmt, dead-code removal, a docstring clarification, and a new unit-test block for the stack-file parser/formatter (which addresses the earlier ask). No new logic to re-verify.
Two concerns on the current state:
1. codecov/patch is failing at 92.28% — 58 uncovered lines in src/commands/sync.rs and 9 in src/config/user/sections.rs. The project CLAUDE.md is explicit: "NEVER merge a PR with failing codecov/patch without explicit user approval." The uncovered clusters worth attention (not all of the 58, just the ones where tests would add meaningful signal):
sync.rsL516–L524 — the inner loop of chained reparenting.sync_cascading_mergescovers one level of integrated-ancestor reparenting; the while-body that walks through multiple consecutive integrated ancestors is never entered. A test where bothpr1andpr2are squash-merged simultaneously whilepr3remains would exercise it.sync.rsL681–L686 — the mid-rebase abort guard (bail!when a worktree is already inREBASE_*state before sync starts).sync.rsL831–L881 — error paths in the--pushand--pruneloops (push failure, prune failure, the warnings printed for them).src/config/user/sections.rs—SyncConfigaccessors that return the hardcoded defaults when theOption<bool>isNone. A couple oflist_configsnapshot assertions would cover these.
2. Exit code on rebase conflict. wt sync currently returns Ok(()) on a rebase conflict (see the inline suggestion below), so the process exits 0 even though the user is left with an unresolved rebase. wt step rebase returns GitError::RebaseConflict in the same situation (non-zero exit), and wt sync && next-step chains will silently proceed past a conflict today. The sync_rebase_conflict snapshot already captures this (success: true, exit_code: 0) — accepting the fix will require regenerating it.
The existing hint message is already user-friendly, so the fix just needs to set a non-zero exit code after printing. The WorktrunkError::AlreadyDisplayed { exit_code: 1 } variant exists for exactly this case (empty Display, exit_code() returns 1) and is used the same way in src/commands/external.rs and src/commands/for_each.rs.
| // Save fork-points for branches processed so far | ||
| let _ = save_fork_points(&repo, &fork_points); | ||
| return Ok(()); |
There was a problem hiding this comment.
return Ok(()) exits the process with status 0 even though the user has an unresolved rebase in the worktree. wt step rebase returns GitError::RebaseConflict for the same condition (non-zero exit), and shell chains like wt sync && ... will silently proceed past the conflict today. Also, let _ = save_fork_points(...) drops any IO error from the save — inconsistent with the ? used on the same call in the happy path a few lines below. Fix both at once:
| // Save fork-points for branches processed so far | |
| let _ = save_fork_points(&repo, &fork_points); | |
| return Ok(()); | |
| // Save fork-points for branches processed so far | |
| save_fork_points(&repo, &fork_points)?; | |
| return Err(worktrunk::git::WorktrunkError::AlreadyDisplayed { exit_code: 1 }.into()); |
(src/commands/external.rs and src/commands/for_each.rs use the same AlreadyDisplayed { exit_code: 1 } pattern after printing their own nicely-formatted error.)
|
Moved to a standalone binary: https://github.com/pablospe/worktrunk-sync — works via the external subcommand dispatch merged in #2054. |
|
Thanks for the update — a standalone binary is a clean fit, and it's nice confirmation that the |
|
Superseded — sync moved to separate repo: https://github.com/pablospe/worktrunk-sync |
Summary
.git/wt/stackfile (git-machete compatible format) for explicit parent trackingStack: 2/3 — depends on #2059 (sync-core). Review the incremental diff:
sync-core...sync-stack-fileTest plan