[Fix] Derive worktree name from -b when no name given#65
Merged
Conversation
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]>
There was a problem hiding this comment.
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.
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.
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 (existingaddArgslogic).-b/--baseflag variable betweenwt addandwt dup. They previously sharedwtBaseBranch, anddup's"main"default overwrote the variable atinittime, sowt add's-beffectively defaulted tomain.wt add'sUse/Long/Exampleto 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/fooreads naturally without repeating the name. Also removes a latent init-order bug wherewt add's base default was not actually"".Repro of the original error
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]:wtBaseBranchcould be renamed towtAddBasefor symmetry withwtDupBase/wtPruneBase. Deferred — not a behavior concern.cmd/worktree.go[BOT-SCOPE]: No cmd-level test for the new zero-arg +-bpath. Deferred for a follow-up test-only PR.