check_linked_checkout() only understands symref-style HEAD (i.e. "ref: refs/heads/master"), however, HEAD may also be a an actual symbolic link (on platforms which support it). To accurately detect if a branch is checked out elsewhere, it needs to handle symbolic link HEAD, as well. Signed-off-by: Eric Sunshine <sunshine@xxxxxxxxxxxxxx> --- New in v2. The new test's title intentionally employs slightly odd grammar to match the grammar of its brother test just above. Test title grammar could be cleaned up in a separate patch, but the current series is already overly long. builtin/checkout.c | 6 +++++- t/t2025-worktree-add.sh | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index 3487712..3326aa8 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -889,7 +889,11 @@ static void check_linked_checkout(const char *branch, const char *id) else strbuf_addf(&path, "%s/HEAD", get_git_common_dir()); - if (strbuf_read_file(&sb, path.buf, 0) >= 0 && + if (!strbuf_readlink(&sb, path.buf, 0)) { + if (!starts_with(sb.buf, "refs/") || + check_refname_format(sb.buf, 0)) + goto done; + } else if (strbuf_read_file(&sb, path.buf, 0) >= 0 && starts_with(sb.buf, "ref:")) { strbuf_remove(&sb, 0, strlen("ref:")); strbuf_trim(&sb); diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh index ead8aa2..9e30690 100755 --- a/t/t2025-worktree-add.sh +++ b/t/t2025-worktree-add.sh @@ -83,6 +83,14 @@ test_expect_success 'die the same branch is already checked out' ' ) ' +test_expect_success SYMLINKS 'die the same branch is already checked out (symlink)' ' + head=$(git -C there rev-parse --git-path HEAD) && + ref=$(git -C there symbolic-ref HEAD) && + rm "$head" && + ln -s "$ref" "$head" && + test_must_fail git -C here checkout newmaster +' + test_expect_success 'not die the same branch is already checked out' ' ( cd here && -- 2.5.0.rc2.378.g0af52e8 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html