Skip to content

Commit 92edf61

Browse files
rjustogitster
authored andcommitted
branch: error message deleting a branch in use
Let's update the error message we show when the user tries to delete a branch which is being used in another worktree, following the guideline reasoned in 4970bed (branch: update the message to refuse touching a branch in-use, 2023-07-21). Signed-off-by: Rubén Justo <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4970bed commit 92edf61

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
262262
const char *path;
263263
if ((path = branch_checked_out(name))) {
264264
error(_("Cannot delete branch '%s' "
265-
"checked out at '%s'"),
265+
"used by worktree at '%s'"),
266266
bname.buf, path);
267267
ret = 1;
268268
continue;

t/t3200-branch.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -942,7 +942,19 @@ test_expect_success 'test deleting branch without config' '
942942
test_expect_success 'deleting currently checked out branch fails' '
943943
git worktree add -b my7 my7 &&
944944
test_must_fail git -C my7 branch -d my7 &&
945-
test_must_fail git branch -d my7 &&
945+
test_must_fail git branch -d my7 2>actual &&
946+
grep "^error: Cannot delete branch .my7. used by worktree at " actual &&
947+
rm -r my7 &&
948+
git worktree prune
949+
'
950+
951+
test_expect_success 'deleting in-use branch fails' '
952+
git worktree add my7 &&
953+
test_commit -C my7 bt7 &&
954+
git -C my7 bisect start HEAD HEAD~2 &&
955+
test_must_fail git -C my7 branch -d my7 &&
956+
test_must_fail git branch -d my7 2>actual &&
957+
grep "^error: Cannot delete branch .my7. used by worktree at " actual &&
946958
rm -r my7 &&
947959
git worktree prune
948960
'

0 commit comments

Comments
 (0)