aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--builtin/branch.c7
-rwxr-xr-xt/t2407-worktree-heads.sh5
2 files changed, 7 insertions, 5 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index 5d00d0b8d3..f875952e7b 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -253,12 +253,11 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
name = mkpathdup(fmt, bname.buf);
if (kinds == FILTER_REFS_BRANCHES) {
- const struct worktree *wt =
- find_shared_symref(worktrees, "HEAD", name);
- if (wt) {
+ const char *path;
+ if ((path = branch_checked_out(name))) {
error(_("Cannot delete branch '%s' "
"checked out at '%s'"),
- bname.buf, wt->path);
+ bname.buf, path);
ret = 1;
continue;
}
diff --git a/t/t2407-worktree-heads.sh b/t/t2407-worktree-heads.sh
index 1fbde05fe2..a5aec1486c 100755
--- a/t/t2407-worktree-heads.sh
+++ b/t/t2407-worktree-heads.sh
@@ -37,7 +37,10 @@ test_expect_success 'refuse to overwrite: checked out in worktree' '
for i in 1 2 3 4
do
test_must_fail git branch -f wt-$i HEAD 2>err
- grep "cannot force update the branch" err || return 1
+ grep "cannot force update the branch" err &&
+
+ test_must_fail git branch -D wt-$i 2>err
+ grep "Cannot delete branch" err || return 1
done
'