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.
This commit is contained in:
1 file changed
+13
-5
@@ -6,7 +6,8 @@
|
||||
# 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 sync [<args>] gt sync <args> 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
|
||||
|
||||
Reference in new issue
Block a user