Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Agent 笔记:Git 删除期间保持工作台可操作

状态:已实现

## 先说结论

用户确认删除分支或移除工作树后,确认弹窗立即关闭,Git 写入在后台继续。相关删除入口在任务结束前保持禁用,编辑、导航和其他工具窗口可以继续使用。

## 问题

Git 命令已经在后台执行,但运行中的确认弹窗继续截获工作台输入。远程分支删除会等待网络,工作树移除也可能耗时。两种情况都会让用户在等待期间无法直接操作工作台。

## 决策

- 提交确认时捕获仓库、目标和所选操作,关闭弹窗,然后使用项目所属的后台任务执行。分支删除在当前项目仍有效时发布结果和刷新列表。
- 对未合并分支或有本地改动的工作树,仍以 Git 返回的结构化拒绝为依据,进入明确的强制确认。后台返回时先检查发起操作的界面和当前弹窗。Git Log 用自己的仓库选择判断,标题栏分支弹窗用它自己的仓库。用户已切走或打开表单时,在通知中心提供审阅入口,弹窗和草稿继续保留。
- 每条通知保留原操作的结果。混合批量结果继续显示成功项与每条失败原因。分支强删确认显示仓库路径、分支名,提交时继续带上原审阅提交。工作树审阅显示 checkout 路径。恢复审阅时以及提交强制移除前,后台用 Core 的最新列表核对路径、分支、HEAD 和移除资格。工作树已有其他写入、目标发生变化或无法读取时,要反馈原因并让用户重新核对。
- 执行结束前继续禁用同一类删除入口。确认弹窗关闭和后台任务结束各自有独立的状态,普通关闭动作不用于提交删除。

例如,确认删除远程分支后可以立即点「项目」,删除完成后再读取更新的引用。要让工作台保持可用,等待期间应释放整个模态弹窗,只禁用它的按钮仍会挡住下面的工作台。

## 考虑过的备选方案

- 在确认弹窗内加进度条和取消按钮。该做法仍会捕获工作台输入,因而保留了原问题。
- 取消确认后直接强制删除。Git 首次拒绝时需要让用户审阅本地改动和目标,原有的额外确认步骤仍有必要。

## 后果

用户可在 Git 等待期间切换面板,删除的结果仍由原来的结果视图和通知反馈。操作遇到 Git 的保护条件时,继续删除需要一次单独的确认动作。

## 验证

- `TestGitDeletionKeepsWorkbenchInteractive` 在后台操作停在可控等待点时向「项目」按钮发送真实点击,断言第一次点击即触发切换。继续执行后检查远程引用或工作树记录已删除。
- `TestGitDeletionFailureLeavesNewBranchDialogOpen` 在远程删除等待时打开新建分支弹窗,验证后来返回的失败只发通知并保留草稿。
- `TestGitDeletionDoesNotForceRemoveReplacementWorktree` 在打开旧通知前和点击强制确认前分别用外部 Git 重新登记同一路径,检查替换工作树及其未跟踪文件仍在。
- 审查回归覆盖同名分支跨仓库、混合批量和脏工作树返回时保留分支草稿,以及从通知打开原结果和二次确认。
- `TestLogForceDeleteRequiresSecondConfirmation` 和 `TestWorktreesRemovalOfAChangedCheckoutAsksToForce` 验证两个强制确认流程。无头截图入口为 `TestVisualGitDeletionInProgress`。

## 适用范围

- `desktop/internal/workbench/branch_delete.go`
- `desktop/internal/workbench/gitlog_view.go`
- `desktop/internal/workbench/gitworktree.go`
8 changes: 8 additions & 0 deletions desktop/internal/i18n/shared.generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 5 additions & 11 deletions desktop/internal/workbench/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ type branchState struct {
search, name, revision ui.Field
// tagMessage is the annotation typed in the new tag dialog.
tagMessage ui.Field
// deleteGen isolates completions from a dismissed or replaced deletion dialog.
deleteGen int
branchSession
}

Expand Down Expand Up @@ -104,13 +102,12 @@ type branchSession struct {
// them; deleteSkipped counts the marked references it leaves out (branch_delete.go).
deleting []core.GitReference
deleteSkipped int
// deleteRoot binds both confirmation steps to the repository originally selected.
deleteRoot string
// deleteUnmerged are only the branches Core refused as unmerged, with their reviewed tips.
deleteUnmerged []branchDeletion
// deleteReport belongs to the operation. Its notification can reopen it after this
// dialog has been dismissed or replaced.
deleteReport *branchDeleteReport
deleteFromNotice bool
deleteError string
deleteList ui.ListState
deleteResults []branchDeletion
deleteResultList ui.ListState

// common are the branches every repository of a project folder with several has
Expand Down Expand Up @@ -375,11 +372,8 @@ func (a *App) beginRevision() {
// cancelBranchDialog closes the open dialog without doing what it asked.
func (a *App) cancelBranchDialog() {
if a.branch.dialog == branchDialogDelete || a.branch.dialog == branchDialogDeleteUnmerged || a.branch.dialog == branchDialogForceDelete || a.branch.dialog == branchDialogDeleteResult {
a.branch.deleteGen++
a.branch.busy = false
a.branch.deleteUnmerged = nil
a.branch.deleteReport = nil
a.branch.deleteError = ""
a.branch.deleteResults = nil
}
a.branch.dialog, a.branch.across = branchDialogNone, false
}
Expand Down
Loading
Loading