pinwheel: Skip worktrees that conflict in wt sync

gt restack stops at a merge conflict mid-rebase, so wt sync left that
worktree half rebased. It now aborts the restack with `gt abort --force`
(without --force it waits for a confirmation prompt), leaving the
worktree as it was, carries on with the rest, and lists the conflicted
worktrees apart from those that failed for other reasons. Restacks run
with --no-interactive so a prompt cannot stall the loop.
This commit is contained in:
Alexander Heldt committed 2026-11-25 15:30:28 +01:00
1 parent 9f45ebfb0c
commit bebeaeb2e1
1 file changed
+16 -4
+16 -4
View File
@@ -10,7 +10,8 @@ wt() {
' a second branch' \
" wt rm [<branch>] remove <branch>'s worktree, or the current one; the branch stays" \
' wt sync [<args>] gt sync <args> in the primary checkout, then gt restack in every' \
' worktree not on main whose PR is not merged'
' worktree not on main whose PR is not merged; one that conflicts' \
' is left as it was and listed at the end'
return
fi
@@ -41,7 +42,7 @@ wt() {
sync)
gt --cwd "$primary" sync "${@:2}" || return
git -C "$primary" worktree prune
local line branch merged failed=()
local line branch merged failed=() conflicts=()
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
@@ -54,15 +55,26 @@ wt() {
print -r -- "${dir:t}: merged, not restacked"
else
print -r -- "${dir:t}:"
gt --cwd "$dir" restack || failed+=("$dir")
if ! gt --cwd "$dir" restack --no-interactive; then
if [[ -d $(git -C "$dir" rev-parse --path-format=absolute --git-path rebase-merge) ]]; then
gt --cwd "$dir" abort --force --no-interactive >/dev/null
print -r -- "wt: aborted, ${dir:t} is left as it was"
conflicts+=("$dir")
else
failed+=("$dir")
fi
fi
fi
;;
esac
done
if (( $#conflicts )); then
print -u2 -l "wt: merge conflicts, not restacked; run gt restack in:" $conflicts
fi
if (( $#failed )); then
print -u2 -l "wt: gt restack failed in:" $failed
return 1
fi
(( $#conflicts + $#failed == 0 ))
;;
-c)
[[ -n $2 ]] || { print -u2 'usage: wt -c <branch>'; return 2 }