@@ -253,12 +253,12 @@ 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) {
+ char *path;
+ if (branch_checked_out(name, &path)) {
error(_("Cannot delete branch '%s' "
"checked out at '%s'"),
- bname.buf, wt->path);
+ bname.buf, path);
+ free(path);
ret = 1;
continue;
}
@@ -26,7 +26,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
'