Skip to content

fix: create worktree when using --from and auto-create on switch#2

Merged
rohoswagger merged 3 commits intorohoswagger:mainfrom
dezren39:fix/worktree-create-from-and-switch
Apr 16, 2026
Merged

fix: create worktree when using --from and auto-create on switch#2
rohoswagger merged 3 commits intorohoswagger:mainfrom
dezren39:fix/worktree-create-from-and-switch

Conversation

@dezren39
Copy link
Copy Markdown
Contributor

@dezren39 dezren39 commented Apr 12, 2026

Summary

  • ez create --from now creates a worktree — Previously --from always skipped worktree creation due to !no_worktree && from.is_none(). The --from flag controls which branch is the parent, not whether a worktree is created.
  • ez switch auto-creates worktrees for managed branches — Previously fell back to git checkout in the main worktree, hijacking it. Now creates a linked worktree for managed branches that don't have one.
  • --no-worktree still works as an explicit opt-out, with or without --from.

Bug report

$ ez create local-timestamp --from main
✓ Created `local-timestamp` from `main`
# ... but "no worktree" in ez list

$ ez switch local-timestamp
✓ Switched to `local-timestamp`
# ... but checked out in main repo dir, not a worktree

Root cause

  1. create.rs:98: let use_worktree = !no_worktree && from.is_none()from.is_none() wrongly disabled worktree creation whenever --from was used.
  2. checkout.rs:81-83: when a branch had no worktree, switch_to() did a raw git checkout instead of creating a worktree.

Changes

  • src/cmd/create.rs — Removed from.is_none() from worktree condition, consolidated 3 code paths into 2 (worktree vs --no-worktree)
  • src/cmd/checkout.rs — Added auto-worktree creation for managed branches without one on switch; trunk still does plain checkout
  • 4 new tests covering both fixes and the --no-worktree opt-out

Two bugs prevented proper worktree management:

1. `ez create --from` never created a worktree because the condition
`!no_worktree && from.is_none()` treated --from as implying no-worktree.
The --from flag controls which branch is the parent, not whether a worktree
is created. Now `ez create feat --from main` creates a worktree at
.worktrees/feat as expected.

2. `ez switch` fell back to `git checkout` for branches without worktrees,
hijacking the main worktree. Now it auto-creates a linked worktree for
managed branches that don't have one, matching the worktree-first design.
…no-switch, duplicate branch, and switch_to edge cases
Copy link
Copy Markdown
Owner

@rohoswagger rohoswagger left a comment

Choose a reason for hiding this comment

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

looks good!

@rohoswagger
Copy link
Copy Markdown
Owner

@dezren39 could you fix up CI for this and then i can go ahead and merge it in :)

Apply rustfmt to checkout.rs and create.rs test code. Add .opencode/ and .worktrees/ to gitignore.
@rohoswagger rohoswagger merged commit 7fc96b4 into rohoswagger:main Apr 16, 2026
4 checks passed
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