Skip to content

Commit 2a49926

Browse files
rjustogitster
authored andcommitted
branch: error message checking out a branch in use
Let's update the error message we show when the user tries to check out 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 92edf61 commit 2a49926

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
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
}

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/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)