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 4970bedef2 (branch: update the message to refuse touching a branch in-use, 2023-07-21). Signed-off-by: Rubén Justo <rjusto@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Rubén Justo committed
Aug 7, 2023 at 22:42 UTC
92edf618709eaee1c3b42481cb478ed00eae1c2b
2 files changed
+14
-2
builtin/branch.c
+1
-1
@@ -262,7 +262,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
262
const char *path;
263
if ((path = branch_checked_out(name))) {
264
error(_("Cannot delete branch '%s' "
265
- "checked out at '%s'"),
265
+ "used by worktree at '%s'"),
266
bname.buf, path);
267
ret = 1;
268
continue;
t/t3200-branch.sh
+13
-1
@@ -942,7 +942,19 @@ test_expect_success 'test deleting branch without config' '
942
test_expect_success 'deleting currently checked out branch fails' '
943
git worktree add -b my7 my7 &&
944
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 &&
958
rm -r my7 &&
959
git worktree prune
960
'