🐛 fix(vscode): 完成列/删 worktree 时自动杀掉占用进程再删目录
This commit is contained in:
1 parent
23e6f67373
commit
29aaabdabf
4 files changed
+133
-41
No files matched your search
@@ -4,7 +4,7 @@ import { execFile } from 'node:child_process'
|
||||
import { commands, Uri, window, workspace } from 'vscode'
|
||||
import { getToken } from '../../auth/secrets'
|
||||
import { detectRepo } from '../../git/remote'
|
||||
import { expandTilde, findProcessesUsingWorktree, removeWorktreeDir, resolveWorktreePath } from '../../git/worktree'
|
||||
import { expandTilde, killProcessesUsingWorktree, removeWorktreeDir, resolveWorktreePath } from '../../git/worktree'
|
||||
import {
|
||||
runImplTabPostCloseHook,
|
||||
runImplTabPreCreateHook,
|
||||
@@ -97,15 +97,18 @@ export async function handleDeleteWorktree(panel: KanbanWebviewPanel, issueNumbe
|
||||
customScriptPath: settingsForHook.worktreePreRemoveScript,
|
||||
})
|
||||
|
||||
// 删前守门:dev server 等仍在写 worktree 的进程会让递归删除撞 ENOTEMPTY。
|
||||
// 命中就别删、别杀进程,只提示,让用户停掉后重试。
|
||||
const procHits = findProcessesUsingWorktree(abs)
|
||||
if (procHits.length > 0) {
|
||||
const list = procHits
|
||||
// 先杀占用进程(dev server 等),再删目录,避免 ENOTEMPTY 竞态。
|
||||
const killed = killProcessesUsingWorktree(abs)
|
||||
if (killed.length > 0) {
|
||||
const list = killed
|
||||
.map(h => `pid ${h.pid}: ${h.cmd.length > 80 ? `${h.cmd.slice(0, 80)}…` : h.cmd}`)
|
||||
.join('\n')
|
||||
void window.showErrorMessage(`有进程仍在占用 worktree,已中止删除。请先停止后重试:\n${list}`)
|
||||
return
|
||||
logger.add({
|
||||
level: 'warn',
|
||||
source: 'panel',
|
||||
message: `删除 worktree 前已杀掉占用进程 (issue #${issueNumber})`,
|
||||
details: list,
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user