Skip to content

[Fix] Derive worktree name from -b when no name given#65

Merged
samzong merged 2 commits intomainfrom
fix/wt-add-derive-name-from-base
Apr 17, 2026
Merged

[Fix] Derive worktree name from -b when no name given#65
samzong merged 2 commits intomainfrom
fix/wt-add-derive-name-from-base

Conversation

@samzong
Copy link
Copy Markdown
Owner

@samzong samzong commented Apr 17, 2026

What's changed?

  • gmc wt add -b <branch> now works without a positional argument; the worktree name defaults to the base-branch value. When the branch already exists, this checks it out directly (existing addArgs logic).
  • Split the -b/--base flag variable between wt add and wt dup. They previously shared wtBaseBranch, and dup's "main" default overwrote the variable at init time, so wt add's -b effectively defaulted to main.
  • Updated wt add's Use / Long / Example to reflect the new optional-name form.

Why

Smoother ergonomics for the common case of creating a worktree from an already-named branch (e.g. PR review, agent-dispatched work): gmc wt add -b feat/foo reads naturally without repeating the name. Also removes a latent init-order bug where wt add's base default was not actually "".

Repro of the original error

$ gmc wt add -b feat/gateway-doctor-memory-rem-harness
Error: requires at least 1 arg(s), only received 0

After this change, the command succeeds and creates a worktree named feat/gateway-doctor-memory-rem-harness (directory: feat--gateway-doctor-memory-rem-harness, per existing dir-name rule).

Considered and deferred

  • cmd/worktree.go [BOT-NIT]: wtBaseBranch could be renamed to wtAddBase for symmetry with wtDupBase / wtPruneBase. Deferred — not a behavior concern.
  • cmd/worktree.go [BOT-SCOPE]: No cmd-level test for the new zero-arg + -b path. Deferred for a follow-up test-only PR.

samzong added 2 commits April 3, 2026 13:48
Fix 7 new lint violations from #63 and #64:
- lll: break long lines in worktree.go, worktree_test.go, prune.go, resource.go
- perfsprint: use errors.New instead of fmt.Errorf for static strings in prune.go
- gocritic/unlambda: simplify exec.Command wrapper in worktree_test.go

Signed-off-by: samzong <[email protected]>
- Allow `gmc wt add -b <branch>` without positional args; worktree name defaults to the base branch value.

- Split the `-b/--base` flag variable between `wt add` and `wt dup` so dup's "main" default no longer pollutes add at init time.

## Considered and deferred

- cmd/worktree.go [BOT-NIT]: wtBaseBranch could be renamed to wtAddBase for symmetry with wtDupBase / wtPruneBase. Deferred — not a behavior concern.
- cmd/worktree.go [BOT-SCOPE]: No cmd-level test for the new zero-arg + -b path. Deferred for a follow-up test-only PR.

Signed-off-by: samzong <[email protected]>
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the worktree add command to allow the worktree name to be derived from the base branch when no positional arguments are provided. It also introduces a separate wtDupBase variable for the dup command's base branch flag and includes several minor refactorings, such as simplifying execCommand assignments and improving error handling consistency. I have no feedback to provide.

@samzong samzong merged commit 36ba51b into main Apr 17, 2026
1 check 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.

1 participant