Conversation
Adds `wt step relocate` to move worktrees to their expected paths based on the `worktree-path` template. Supports dry-run preview, filtering by branch name, and auto-committing dirty worktrees. Handles special case of main worktree by switching to default branch and creating a new worktree.
Implement full swap/cycle handling and non-worktree blocker management for relocate command. Adds `--clobber` flag to automatically backup blocking paths, dependency graph processing to handle worktree cycles via temporary locations, and comprehensive spec documentation. Key changes: - Add `--clobber` flag to back up non-worktree paths at target locations - Implement cycle detection and resolution using temp directory - Build dependency graph to coordinate multi-worktree moves - Handle main worktree relocation by creating new worktree + switching - Add test cases for swap, clobber, and cycle scenarios - Canonicalize temp home paths on macOS for snapshot consistency
- Refuse to clobber existing worktrees (would corrupt git metadata) - Prefer non-main worktree when breaking cycles (git can't move main) - Sanitize branch names for temp paths (feature/foo -> feature-foo) - Track original path for shell cd in temp-relocated worktrees - Show template errors as warnings instead of silently dropping Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Tests the commit_worktree_changes function by configuring a mock LLM and verifying that dirty worktrees are auto-committed before relocating. Co-Authored-By: Claude <noreply@anthropic.com>
- Change unreachable defensive code to expect() with explanation - Simplify multi-line cformat! calls to single-line (improves LLVM coverage) - Add test_relocate_mixed_success_and_skip to cover "relocated X, skipped Y" path - Add test_relocate_dirty_with_commit to cover commit_worktree_changes function Co-Authored-By: Claude <noreply@anthropic.com>
- Remove shell directory update for temp-to-final worktree moves (rare case where user is inside a worktree during cycle resolution) - Simplify summary pluralization with inline closure - Remove unused original_path tracking from temp_relocated Co-Authored-By: Claude <noreply@anthropic.com>
Extract multi-line cformat! macro calls to single-line variables to improve LLVM coverage instrumentation. Co-Authored-By: Claude <noreply@anthropic.com>
The early return when no staged changes was unreachable - if is_dirty() returned true, git add -A must stage something. Removing improves coverage and follows fail-fast principles. Co-Authored-By: Claude <noreply@anthropic.com>
- Remove redundant exists() check before create_dir_all - Extract cformat! to single-line variable in commit_worktree_changes Co-Authored-By: Claude <noreply@anthropic.com>
Reverts format_path_for_display changes that were unrelated to step relocate and were reducing coverage percentage since they're in error paths. Co-Authored-By: Claude <noreply@anthropic.com>
Resolve merge conflict in step_commands.rs imports. Migrate output API: crate::output::print() → eprintln!() Co-Authored-By: Claude <noreply@anthropic.com>
Fixes identified by adversarial testing: 1. Empty default branch validation - fails early with actionable error instead of confusing "git checkout ''" errors 2. Same-target conflict handling - `is_target_empty` now returns `Option<bool>` to gracefully skip when target is unexpectedly blocked (TOCTOU race or same-target conflict) 3. Main worktree rollback - if `git worktree add` fails after checkout, restore the original branch Adds test for same-target scenario that previously panicked. Co-Authored-By: Claude <noreply@anthropic.com>
Owner
Author
|
@claude move the plan to a spec in a rust module; then remove it |
Collaborator
|
Claude finished @max-sixty's task in 6m 16s —— View job Moving plan to Rust module spec
SummarySuccessfully moved the step relocate plan from Changes:
Testing:
The specification is now directly attached to the implementation, making it more discoverable for developers and keeping it synchronized with the code. --- | Branch: reset-locations |
Moved the comprehensive plan from .claude/plans/step-relocate-spec.md to a Rust doc comment on the step_relocate function. This makes the specification more discoverable and keeps it synchronized with the implementation. The doc comment now includes: - Complete flag descriptions - Detailed algorithm explanation - Multiple scenario examples (swap, chain, mixed, clobber, main worktree) - Implementation notes - Test case list Co-authored-by: Maximilian Roos <max-sixty@users.noreply.github.com>
Add tests for: - Template expansion error handling (invalid variable) - Empty default branch validation (non-existent configured branch) These cover lines 844-847 and 890-895 in step_commands.rs that were flagged by codecov/patch. Co-Authored-By: Claude <noreply@anthropic.com>
- Use gutter formatting for template error details (per output guidelines) - Fix misleading summary when template errors occurred - Show source path in temp-relocated worktree success messages - Use bright-black styling for flags in hints (--commit, --clobber) - Use concrete example in default branch error message Co-Authored-By: Claude <noreply@anthropic.com>
Per output guidelines: every user-facing message needs symbol or gutter. The dry-run preview now uses gutter formatting instead of plain indentation. Co-Authored-By: Claude <noreply@anthropic.com>
The error message now suggests 'wt config state default-branch set main' instead of the raw git config command. Co-Authored-By: Claude <noreply@anthropic.com>
Extract commit staging and execution into CommitGenerator to eliminate duplicate commit logic in step_relocate. Add show_progress parameter to control progress message display for bulk operations. Add repo() accessor to WorkingTree for repository access.
…ypes Split the 500-line monolithic step_relocate function into a clean pipeline: - gather_candidates() finds worktrees not at expected paths - validate_candidates() checks locked/dirty, handles --commit - RelocationExecutor encapsulates the dependency graph algorithm New types document each stage: RelocationCandidate, ValidatedCandidate, GatherResult, ValidationResult. The complex swap/cycle resolution logic is now isolated in RelocationExecutor with clear methods for each phase. Co-authored-by: Claude <noreply@anthropic.com>
Resolved conflict in resolve.rs: kept pub(crate) visibility for paths_match (needed by relocate.rs module) while accepting main's removal of redundant use statement. Co-authored-by: Claude <noreply@anthropic.com>
Resolved conflicts: - src/main.rs: Combined imports (handle_logs_get from main, step_relocate from HEAD) - tests/common/mod.rs: Kept main's refactor to use setup_snapshot_settings_impl (which already handles canonicalization internally) Co-Authored-By: Claude <noreply@anthropic.com>
The test was using the old `args` field which no longer exists. The command should be a complete shell string that receives the prompt via stdin. Co-Authored-By: Claude <noreply@anthropic.com>
Resolved conflict in paths_match by: - Keeping pub(crate) visibility from this branch - Using improved canonicalize_with_parents from main Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
wt step relocatecommand to move worktrees to their expected paths based on theworktree-pathtemplate--clobberflag to backup non-worktree paths at target locations--commitflag to auto-commit dirty worktrees before relocatingKey behaviors
Swap handling: When worktrees are at each other's expected locations (e.g.,
alpha@repo.beta,beta@repo.alpha), the command automatically resolves via a temp location.Main worktree: When main worktree has a non-default branch checked out, creates a new linked worktree at the expected path and switches main back to default branch.
Flags:
--dry-run: Preview what would be moved--commit: Auto-commit dirty worktrees before relocating--clobber: Backup non-worktree paths to<path>.bak-<timestamp>Safety:
--commit --clobbershould handle most scenarios without failing.Also includes
_PARENT_/<dir>instead of[PROJECT_ID])/var→/private/varsymlinksTest plan