Skip to content

Commit f5f23a4

Browse files
committed
Merge branch 'rj/branch-in-use-error-message'
A message written in olden time prevented a branch from getting checked out saying it is already checked out elsewhere, but these days, we treat a branch that is being bisected or rebased just like a branch that is checked out and protect it. Rephrase the message to say that the branch is in use. * rj/branch-in-use-error-message: branch: error message checking out a branch in use branch: error message deleting a branch in use
2 parents 43c8a30 + 2a49926 commit f5f23a4

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ void die_if_checked_out(const char *branch, int ignore_current_worktree)
838838

839839
if (is_shared_symref(worktrees[i], "HEAD", branch)) {
840840
skip_prefix(branch, "refs/heads/", &branch);
841-
die(_("'%s' is already checked out at '%s'"),
841+
die(_("'%s' is already used by worktree at '%s'"),
842842
branch, worktrees[i]->path);
843843
}
844844
}

builtin/branch.c

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

t/t2400-worktree-add.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ test_expect_success '"add" worktree creating new branch' '
121121
test_expect_success 'die the same branch is already checked out' '
122122
(
123123
cd here &&
124-
test_must_fail git checkout newmain
124+
test_must_fail git checkout newmain 2>actual &&
125+
grep "already used by worktree at" actual
125126
)
126127
'
127128

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
'

t/t3400-rebase.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ test_expect_success 'refuse to switch to branch checked out elsewhere' '
421421
git checkout main &&
422422
git worktree add wt &&
423423
test_must_fail git -C wt rebase main main 2>err &&
424-
test_i18ngrep "already checked out" err
424+
test_i18ngrep "already used by worktree at" err
425425
'
426426

427427
test_expect_success MINGW,SYMLINKS_WINDOWS 'rebase when .git/logs is a symlink' '

0 commit comments

Comments
 (0)