@@ -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;
}
@@ -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
'