diff --git a/hosts/pinwheel/modules/work/wt.zsh b/hosts/pinwheel/modules/work/wt.zsh index 80bf255..39a679e 100644 --- a/hosts/pinwheel/modules/work/wt.zsh +++ b/hosts/pinwheel/modules/work/wt.zsh @@ -10,7 +10,8 @@ wt() { ' a second branch' \ " wt rm [] remove 's worktree, or the current one; the branch stays" \ ' wt sync [] gt sync 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 '; return 2 }