From b21c943b04d2ca5b0371befc654ad5a5c419a0ed Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Mon, 23 Nov 2026 08:14:32 +0100 Subject: [PATCH] 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. --- hosts/pinwheel/modules/work/wt.zsh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/hosts/pinwheel/modules/work/wt.zsh b/hosts/pinwheel/modules/work/wt.zsh index 3fdef9a..c19d3c1 100644 --- a/hosts/pinwheel/modules/work/wt.zsh +++ b/hosts/pinwheel/modules/work/wt.zsh @@ -6,6 +6,7 @@ # wt -c 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 [] remove 's worktree, or the current one; the branch stays +# wt sync [] gt sync , 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 '; return 2 } dir=$primary.worktrees/${2//\//-}