From 67eb18c890cc65b9f8ec1b04227dba6c9e14a96f Mon Sep 17 00:00:00 2001 From: Alexander Heldt Date: Tue, 24 Nov 2026 10:19:04 +0100 Subject: [PATCH] pinwheel: Run `wt sync` from the primary checkout In a worktree, `gt sync` deletes a merged current branch by first switching to main, which git refuses while the primary has main checked out. `wt sync` now runs `gt sync` in the primary, which leaves a merged branch checked out in a worktree alone. Worktrees whose PR is merged are no longer restacked. They stay until removed with `wt rm`, so a session in one can still be resumed. The merged PRs are read from gt's `.graphite_pr_info` cache, which `gt sync` has just refreshed; gt has no command that lists them. --- hosts/pinwheel/modules/work/wt.zsh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/hosts/pinwheel/modules/work/wt.zsh b/hosts/pinwheel/modules/work/wt.zsh index c19d3c1..dc38e9b 100644 --- a/hosts/pinwheel/modules/work/wt.zsh +++ b/hosts/pinwheel/modules/work/wt.zsh @@ -6,7 +6,8 @@ # 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 sync [] gt sync in the primary checkout, then gt restack in every worktree +# not on main whose PR is not merged wt() { local primary dir primary=$(git rev-parse --path-format=absolute --git-common-dir) || return @@ -33,15 +34,22 @@ wt() { fi ;; sync) - gt sync "${@:2}" || return - local line failed=() + gt --cwd "$primary" sync "${@:2}" || return + local line branch merged failed=() + merged=(${(f)"$(jq -r '.prInfos[] | select(.state == "MERGED") | .headRefName' \ + "$primary/.git/.graphite_pr_info" 2>/dev/null)"}) 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") + branch=${line#branch refs/heads/} + if (( ${merged[(Ie)$branch]} )); then + print -r -- "${dir:t}: merged, not restacked" + else + print -r -- "${dir:t}:" + gt --cwd "$dir" restack || failed+=("$dir") + fi ;; esac done