pinwheel: Add wt sync to restack every worktree
`gt sync` skips branches checked out in another worktree, so a stack living in one stays on the old main. `wt sync` runs `gt sync`, then `gt restack` in each worktree not on main. A conflict in one worktree leaves it mid-rebase and does not stop the others; the failed worktrees are listed at the end and the exit status is 1.
This commit is contained in:
1 file changed
+19
@@ -6,6 +6,7 @@
|
||||
# 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>, then gt restack in every worktree not on main
|
||||
wt() {
|
||||
local primary dir
|
||||
primary=$(git rev-parse --path-format=absolute --git-common-dir) || return
|
||||
@@ -31,6 +32,24 @@ wt() {
|
||||
cd "$primary"
|
||||
fi
|
||||
;;
|
||||
sync)
|
||||
gt sync "${@:2}" || return
|
||||
local line failed=()
|
||||
for line in "${(@f)$(git worktree list --porcelain)}"; do
|
||||
case $line in
|
||||
'worktree '*) dir=${line#worktree } ;;
|
||||
'branch refs/heads/main') ;;
|
||||
'branch '*)
|
||||
print -r -- "${dir:t}:"
|
||||
gt --cwd "$dir" restack || failed+=("$dir")
|
||||
;;
|
||||
esac
|
||||
done
|
||||
if (( $#failed )); then
|
||||
print -u2 -l "wt: gt restack failed in:" $failed
|
||||
return 1
|
||||
fi
|
||||
;;
|
||||
-c)
|
||||
[[ -n $2 ]] || { print -u2 'usage: wt -c <branch>'; return 2 }
|
||||
dir=$primary.worktrees/${2//\//-}
|
||||
|
||||
Reference in new issue
Block a user