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