diff --git a/core/commands/branch.py b/core/commands/branch.py index f8ec471e8..88e815b88 100644 --- a/core/commands/branch.py +++ b/core/commands/branch.py @@ -39,8 +39,8 @@ """ EXTRACT_COMMIT = re.compile(r"\(was (.+)\)") -NOT_MERGED_WARNING = re.compile(r"The branch.*is not fully merged\.") -CANT_DELETE_CURRENT_BRANCH = re.compile(r"Cannot delete branch .+ checked out at ") +NOT_MERGED_WARNING = re.compile(r"the branch.*is not fully merged\.", re.I) +CANT_DELETE_USED_BRANCH = re.compile(r"cannot delete branch .+ (checked out|used by worktree) at ", re.I) def just(value): @@ -172,7 +172,10 @@ def run(self, branch, force=False): if NOT_MERGED_WARNING.search(e.stderr): self.offer_force_deletion(branch) return - if CANT_DELETE_CURRENT_BRANCH.search(e.stderr): + if ( + CANT_DELETE_USED_BRANCH.search(e.stderr) + and branch == self.get_current_branch_name() + ): self.offer_detaching_head(branch) return e.show_error_panel()