]> git.ipfire.org Git - thirdparty/git.git/commitdiff
branch: error message deleting a branch in use
authorRubén Justo <rjusto@gmail.com>
Mon, 7 Aug 2023 20:42:36 +0000 (22:42 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 Aug 2023 21:22:11 +0000 (14:22 -0700)
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>
builtin/branch.c
t/t3200-branch.sh

index e8ff3ecc072a3d91ce45e8f531ce840a1519b438..a399256675b6af15076d31e39bfefc2f5148ee90 100644 (file)
@@ -262,7 +262,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
                        const char *path;
                        if ((path = branch_checked_out(name))) {
                                error(_("Cannot delete branch '%s' "
-                                       "checked out at '%s'"),
+                                       "used by worktree at '%s'"),
                                      bname.buf, path);
                                ret = 1;
                                continue;
index daf1666df7adb9594c50445764440ad339f43645..080e4f24a6e2b1a238cfc7f340579b4eec2066d3 100755 (executable)
@@ -942,7 +942,19 @@ test_expect_success 'test deleting branch without config' '
 test_expect_success 'deleting currently checked out branch fails' '
        git worktree add -b my7 my7 &&
        test_must_fail git -C my7 branch -d my7 &&
-       test_must_fail git branch -d my7 &&
+       test_must_fail git branch -d my7 2>actual &&
+       grep "^error: Cannot delete branch .my7. used by worktree at " actual &&
+       rm -r my7 &&
+       git worktree prune
+'
+
+test_expect_success 'deleting in-use branch fails' '
+       git worktree add my7 &&
+       test_commit -C my7 bt7 &&
+       git -C my7 bisect start HEAD HEAD~2 &&
+       test_must_fail git -C my7 branch -d my7 &&
+       test_must_fail git branch -d my7 2>actual &&
+       grep "^error: Cannot delete branch .my7. used by worktree at " actual &&
        rm -r my7 &&
        git worktree prune
 '