🐛 fix(vscode): worktree 清理改 rm -rf + prune,绕开 gitignored 产物导致的目录非空
git worktree remove 只删跟踪文件+admin 注册,不删 .next/node_modules 等 gitignored 产物,删完残留把目录撑住、最后 rmdir 撞 ENOTEMPTY。新增 removeWorktreeDir(带路径护栏的递归强删 + git worktree prune),替换 3 处 worktree remove 调用点。
This commit is contained in:
1 parent
cace658ac1
commit
235cd9ea65
3 files changed
+47
-57
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, resolveWorktreePath } from '../../git/worktree'
|
||||
import { expandTilde, removeWorktreeDir, resolveWorktreePath } from '../../git/worktree'
|
||||
import {
|
||||
runImplTabPostCloseHook,
|
||||
runImplTabPreCreateHook,
|
||||
@@ -59,10 +59,8 @@ export async function handleOpenWorktree(panel: KanbanWebviewPanel, relPath: str
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirm + run `git worktree remove <abs>` (no --force), then clear
|
||||
* `worktreePath`/`branch` from the issue's state JSON and refresh the
|
||||
* board. If `git` rejects due to uncommitted changes we surface stderr
|
||||
* verbatim — the user can resolve manually and re-try.
|
||||
* Confirm + 递归强删 worktree 目录(removeWorktreeDir),然后清掉 state JSON 里的
|
||||
* `worktreePath`/`branch` 并刷新看板。删除失败(如权限、护栏拦截)把错误弹给用户。
|
||||
*/
|
||||
export async function handleDeleteWorktree(panel: KanbanWebviewPanel, issueNumber: number, relPath: string): Promise<void> {
|
||||
const workspaceRoot = workspace.workspaceFolders?.[0]?.uri.fsPath
|
||||
@@ -94,25 +92,11 @@ export async function handleDeleteWorktree(panel: KanbanWebviewPanel, issueNumbe
|
||||
})
|
||||
|
||||
try {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
execFile(
|
||||
'git',
|
||||
['-C', workspaceRoot, 'worktree', 'remove', abs],
|
||||
{ timeout: 30_000 },
|
||||
(err, _stdout, stderr) => {
|
||||
if (err) {
|
||||
const detail = (stderr ?? '').trim() || err.message
|
||||
reject(new Error(detail))
|
||||
return
|
||||
}
|
||||
resolve()
|
||||
},
|
||||
)
|
||||
})
|
||||
await removeWorktreeDir(workspaceRoot, abs)
|
||||
}
|
||||
catch (err) {
|
||||
const message = err instanceof Error ? err.message : String(err)
|
||||
void window.showErrorMessage(`git worktree remove 失败: ${message}`)
|
||||
void window.showErrorMessage(`删除 worktree 失败: ${message}`)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user