From a073b8712c8e2626532613923602b6cb1608359e Mon Sep 17 00:00:00 2001 From: weichen Date: Wed, 30 Sep 2026 03:27:06 +0000 Subject: [PATCH] Teach task-finish to recycle submodule-bearing worktrees Why: git refuses to remove a worktree with initialized submodules; the first real dogfood run of task-finish hit this on the empty-list fix task. Evidence: the fix task's worktree recycled only after manual force-remove; deinit-then-remove path exercised on the same state afterwards. Impact: finish deinitializes submodules, removes, prunes, and deletes the remote branch; unmerged-result guard unchanged. Refs: .task/fix-empty-list-json.md --- scripts/task.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/task.sh b/scripts/task.sh index e03ec77a..6d4b3473 100755 --- a/scripts/task.sh +++ b/scripts/task.sh @@ -126,9 +126,12 @@ cmd_finish() { git merge-base --is-ancestor "$head" "origin/${TARGET_BRANCH}" || die "分支未合入 origin/${TARGET_BRANCH}——先走 PR 合入;放弃则用 --abandon " echo "[verified] ${branch} 已包含于 origin/${TARGET_BRANCH};成果已落盘" fi - git -C "$mainrepo" worktree remove "$PWD" && git -C "$mainrepo" branch -d "$branch" 2>/dev/null || git -C "$mainrepo" branch -D "$branch" + git submodule deinit --all -f >/dev/null 2>&1 || true + git -C "$mainrepo" worktree remove "$PWD" 2>/dev/null || { echo "finish: worktree remove 失败(含未清理内容)——已验证合入,可手动 rm -rf 后 git worktree prune" >&2; exit 1; } + git -C "$mainrepo" branch -d "$branch" 2>/dev/null || git -C "$mainrepo" branch -D "$branch" git -C "$mainrepo" worktree prune - echo "[recycled] worktree 与分支 ${branch} 已回收($(date -u +%FT%TZ))" + git push -q --delete origin "$branch" 2>/dev/null || true + echo "[recycled] worktree 与分支 ${branch} 已回收(本地+远端,$(date -u +%FT%TZ))" } case "${1:-}" in