feat: add 'Remove worktree and branch' option when deleting a branch checked out by a worktree

When deleting a branch that is currently checked out by a worktree,
users previously had to remove the worktree first, then delete the
branch in a second step. This adds a new menu option that combines
both operations into a single action.

Closes #5205
This commit is contained in:
Hermes Semantic Memory 2026-04-30 09:32:42 +08:00
parent b4f79851db
commit 1f7edd5efb
2 changed files with 12 additions and 0 deletions

View file

@ -240,6 +240,16 @@ func (self *BranchesHelper) promptWorktreeBranchDelete(selectedBranch *models.Br
return self.worktreeHelper.Remove(worktree, false)
},
},
{
Label: self.c.Tr.RemoveWorktreeAndBranch,
Tooltip: self.c.Tr.RemoveWorktreeTooltip,
OnPress: func() error {
if err := self.worktreeHelper.Remove(worktree, false); err != nil {
return err
}
return self.c.Git().Branch.LocalDelete([]string{selectedBranch.Name}, true)
},
},
},
})
}

View file

@ -866,6 +866,7 @@ type TranslationSet struct {
DetachWorktreeTooltip string
Switching string
RemoveWorktree string
RemoveWorktreeAndBranch string
RemoveWorktreeTitle string
DetachWorktree string
DetachingWorktree string
@ -1990,6 +1991,7 @@ func EnglishTranslationSet() *TranslationSet {
DetachWorktreeTooltip: "This will run `git checkout --detach` on the worktree so that it stops hogging the branch, but the worktree's working tree will be left alone.",
Switching: "Switching",
RemoveWorktree: "Remove worktree",
RemoveWorktreeAndBranch: "Remove worktree and branch",
RemoveWorktreeTitle: "Remove worktree",
RemoveWorktreePrompt: "Are you sure you want to remove worktree '{{.worktreeName}}'?",
ForceRemoveWorktreePrompt: "'{{.worktreeName}}' contains modified or untracked files, or submodules (or all of these). Are you sure you want to remove it?",