Repository navigation
feat: Explicit --base/--checkout Split for wt create - #33
Conversation
The positional [branch] arg silently overloaded two meanings: an unused name created a new branch, an existing branch name checked it out in-place with no warning. Add --checkout <branch> as the explicit opt-in for checking out an existing branch; the positional now only ever creates a new branch and errors if the name already exists locally or remotely.
There was a problem hiding this comment.
Pull request overview
This PR removes the ambiguous “create-or-checkout” behavior from wt create’s positional [branch] argument by making it new-branch-only, and adds an explicit --checkout <branch> flag for the existing-branch worktree flow. It also enforces hard errors for conflicting selectors (--checkout with positional, and --checkout with --base), splits the internal worktree creation API into two mode-explicit functions with sentinel errors, and updates tests/docs to match the new CLI contract.
Changes:
- Split
wt createbranch selection into explicit modes: positional creates new branches only;--checkoutis required for existing branches. - Introduce sentinel errors in
internal/worktreeand map them toExitInvalidArgsmessaging incmd/wt/create.go. - Update integration/unit tests and documentation/specs to reflect the new surface and error/compatibility matrix.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/internal/worktree/crud.go | Adds sentinel errors and splits worktree creation into CreateNewBranchWorktree vs CheckoutBranchWorktree. |
| src/cmd/wt/create.go | Adds --checkout, enforces selector conflicts, simplifies --base validation, and routes to the new internal APIs. |
| src/cmd/wt/create_test.go | Updates existing tests for --checkout and adds coverage for new error/constraint cases. |
| src/cmd/wt/list_test.go | Updates create invocations to use --checkout for existing branches. |
| src/cmd/wt/integration_test.go | Updates integration flow to use --checkout for existing-branch setup. |
| src/cmd/wt/edge_test.go | Updates special-character branch test to use --checkout for existing branches. |
| src/cmd/wt/delete_test.go | Updates setup worktree creation to use --checkout for existing branch. |
| README.md | Updates CLI summary, scenario table, and gotchas to match new semantics. |
| docs/specs/cli-surface.md | Documents --checkout, new positional semantics, and updated exit-code cases. |
| docs/specs/worktree-layout.md | Updates branch↔worktree relationship examples to use --checkout for existing branches. |
| docs/site/workflows.md | Updates site workflow docs for the new explicit checkout behavior. |
| docs/memory/wt-cli/create-branch-semantics.md | Adds a new memory/contract doc capturing the new branch-selection behavior. |
| docs/memory/wt-cli/index.md | Adds the new memory doc to the index. |
| docs/memory/wt-cli/init-failure-contract.md | Cross-references the new create-branch-semantics memory doc. |
| docs/memory/wt-cli/create-output-phases.md | Updates sibling-memory references to include the new branch-semantics contract. |
| fab/changes/260717-2af2-explicit-base-checkout-flags/* | Adds fab change tracking artifacts (intake/plan/status/history). |
Comments suppressed due to low confidence (1)
src/internal/worktree/crud.go:120
- CheckoutBranchWorktree calls EnsureWorktreesDir before determining whether the target branch exists. On the new ErrBranchNotFound path this can still create ctx.WorktreesDir on disk, contradicting the comment (“creates nothing”) and leaving state behind for a failed
wt create --checkout <missing>in repos that don’t yet have the worktrees directory.
func CheckoutBranchWorktree(branch, name string, ctx *RepoContext, rb *Rollback) (string, error) {
if err := EnsureWorktreesDir(ctx.WorktreesDir); err != nil {
return "", err
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| When BRANCH is omitted, creates an exploratory worktree with a random name on a | ||
| new branch of the same name. |
There was a problem hiding this comment.
Fixed — updated the bare-mode help text to note that the worktree/branch name is random by default or the value of --worktree-name when supplied. (bd92076)
Meta
2af2excludes
fab/,docs/· generated by fab-kit v2.15.3Pipeline: intake ✓ → apply ✓ → review ✓ → hydrate ✓ → ship → review-pr
Summary
wt create's trailing positional argument silently overloaded two meanings: an unused name created a new branch, while an existing branch name checked it out directly in-place with no warning — dangerous for shared/collector branches. This change splits the two behaviors into explicit flags: the positional now only ever creates a new branch (erroring if the name already exists locally or remotely), and a new--checkout <branch>flag is the explicit opt-in for checking out an existing branch.Changes
[branch]becomes new-branch-only — errors withExitInvalidArgsif the name already exists locally or remotely, pointing at--checkout--checkout <branch>flag — explicit opt-in to put the new worktree on an existing local or remote branch, reusing today's existing-branch paths--checkoutwith the positional, or with an incompatible--base) are now hard errors instead of silent/impossible statescmd/internalseam split:CreateBranchWorktreebecomes two explicit internal functions (CreateNewBranchWorktree,CheckoutBranchWorktree), each returning a typed sentinel error thatcmd/create.gomaps to theExitInvalidArgscopydocs/specs/cli-surface.mdanddocs/specs/worktree-layout.mdreflect the new flag and positional semanticsfab batch switchrelies on the old dual-semantics positional and will fail with exit 2 once an existing branch is passed without--checkout; migration is a coordinated follow-up in the fab-kit repo