Skip to content

feat: Explicit --base/--checkout Split for wt create - #33

Merged
sahil-noon merged 4 commits into
mainfrom
260717-2af2-explicit-base-checkout-flags
Jul 17, 2026
Merged

sahil-noon merged 4 commits into
mainfrom
260717-2af2-explicit-base-checkout-flags

Conversation

@sahil-noon

Copy link
Copy Markdown
Collaborator

Meta

Change ID Type Confidence Plan Review
2af2 feat 4.3/5.0 14/14 tasks, 18/18 acceptance ✓ ✓ 1 cycle
Impact +/− Net
raw +1013 / −143 +870
true +249 / −118 +131
└ impl +154 / −67 +87
└ tests +95 / −51 +44

excludes fab/, docs/ · generated by fab-kit v2.15.3

Pipeline: 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

  • Positional [branch] becomes new-branch-only — errors with ExitInvalidArgs if the name already exists locally or remotely, pointing at --checkout
  • New --checkout <branch> flag — explicit opt-in to put the new worktree on an existing local or remote branch, reusing today's existing-branch paths
  • Conflicting selectors (--checkout with the positional, or with an incompatible --base) are now hard errors instead of silent/impossible states
  • cmd/internal seam split: CreateBranchWorktree becomes two explicit internal functions (CreateNewBranchWorktree, CheckoutBranchWorktree), each returning a typed sentinel error that cmd/create.go maps to the ExitInvalidArgs copy
  • Docs updated: docs/specs/cli-surface.md and docs/specs/worktree-layout.md reflect the new flag and positional semantics
  • Breaking change: fab-kit's fab batch switch relies 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

sahil87 added 2 commits July 17, 2026 13:36
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.
@sahil-noon
sahil-noon marked this pull request as ready for review July 17, 2026 08:10
@sahil-noon
sahil-noon requested a review from Copilot July 17, 2026 08:10

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 create branch selection into explicit modes: positional creates new branches only; --checkout is required for existing branches.
  • Introduce sentinel errors in internal/worktree and map them to ExitInvalidArgs messaging in cmd/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.

Comment thread src/cmd/wt/create.go Outdated
Comment on lines +34 to +35
When BRANCH is omitted, creates an exploratory worktree with a random name on a
new branch of the same name.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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)

@sahil-noon
sahil-noon merged commit 9f0c3f2 into main Jul 17, 2026
2 checks passed
@sahil-noon
sahil-noon deleted the 260717-2af2-explicit-base-checkout-flags branch July 17, 2026 08:35
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.

3 participants