pinwheel: Add wt --help and reject unknown wt options

An unknown option such as `-b` or `--help` was taken as a branch name
and passed on to `git worktree add`, which read it as its own option:
`--help` printed git's usage and `-b` failed asking for a value. `wt`
now prints its own usage for `-h`/`--help`, moved there from the
comment at the top of the file, and rejects any other option.
This commit is contained in:
Alexander Heldt committed 2026-11-24 10:33:11 +01:00
1 parent 67eb18c890
commit 3d2208f432
1 file changed
+17 -8
+17 -8
View File
@@ -1,14 +1,19 @@
# Git worktrees beside the primary checkout, one per branch: ~/code/work/backend's live in
# ~/code/work/backend.worktrees/<branch>.
#
# wt list worktrees
# wt <branch> cd to the worktree that has <branch>, adding one if none has it
# wt -c <branch> new branch off main, tracked by gt, in a new worktree; make its first
# commit with `gt modify -a`, since `gt create` would stack a second branch
# wt rm [<branch>] remove <branch>'s worktree, or the current one; the branch stays
# wt sync [<args>] gt sync <args> in the primary checkout, then gt restack in every worktree
# not on main whose PR is not merged
wt() {
if [[ $1 == -h || $1 == --help ]]; then
print -rl -- \
'usage: wt list worktrees' \
' wt <branch> cd to the worktree that has <branch>, adding one if none has it' \
' wt -c <branch> new branch off main, tracked by gt, in a new worktree; make its' \
' first commit with `gt modify -a`, since `gt create` would stack' \
' a second branch' \
" wt rm [<branch>] remove <branch>'s worktree, or the current one; the branch stays" \
' wt sync [<args>] gt sync <args> in the primary checkout, then gt restack in every' \
' worktree not on main whose PR is not merged'
return
fi
local primary dir
primary=$(git rev-parse --path-format=absolute --git-common-dir) || return
primary=${primary:h}
@@ -66,6 +71,10 @@ wt() {
_wt_setup "$primary" "$dir" &&
cd "$dir"
;;
-*)
print -u2 "wt: unknown option $1, see wt --help"
return 2
;;
*)
dir=$(_wt_dir "$1")
if [[ -z $dir ]]; then