worktree: allow the main brach of a bare repository to be checked out

In bare repositories, get_worktrees() still returns the main repository, so git worktree list can show it. ignore it in find_shared_symref so we can still check out the main branch. Signed-off-by: Dennis Kaarsemaker <dennis@kaarsemaker.net> Acked-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Dennis Kaarsemaker committed Oct 12, 2016 at 18:41 UTC 171c646f8c6484cca76933ebe8a6af52df47277d
2 files changed +10
t/t2025-worktree-add.sh
+8
@@ -138,6 +138,14 @@ test_expect_success 'checkout from a bare repo without "add"' '
138 )
139 '
140
141 +test_expect_success '"add" default branch of a bare repo' '
142 + (
143 + git clone --bare . bare2 &&
144 + cd bare2 &&
145 + git worktree add ../there3 master
146 + )
147 +'
148 +
149 test_expect_success 'checkout with grafts' '
150 test_when_finished rm .git/info/grafts &&
151 test_commit abc &&
worktree.c
+2
@@ -345,6 +345,8 @@ const struct worktree *find_shared_symref(const char *symref,
345
346 for (i = 0; worktrees[i]; i++) {
347 struct worktree *wt = worktrees[i];
348 + if (wt->is_bare)
349 + continue;
350
351 if (wt->is_detached && !strcmp(symref, "HEAD")) {
352 if (is_worktree_being_rebased(wt, target)) {