worktree.c: check whether branch is bisected in another worktree
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Fri, 22 Apr 2016 13:01:35 +0000 (20:01 +0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 22 Apr 2016 21:09:39 +0000 (14:09 -0700)
Similar to the rebase case, we want to detect if "HEAD" in some worktree
is being bisected because

1) we do not want to checkout this branch in another worktree, after
bisect is done it will want to go back to this branch

2) we do not want to delete the branch is either or git bisect will
fail to return to the (long gone) branch

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t2025-worktree-add.sh
worktree.c
index da54327f5da14d4778ad8603a34b22cf96f96e5c..8f53944cb21e1d9e3097a8bb5c3aa6ee016a46f1 100755 (executable)
@@ -263,4 +263,17 @@ test_expect_success 'check out from current worktree branch ok' '
        )
 '
 
+test_expect_success 'checkout a branch under bisect' '
+       git worktree add under-bisect &&
+       (
+               cd under-bisect &&
+               git bisect start &&
+               git bisect bad &&
+               git bisect good HEAD~2 &&
+               git worktree list | grep "under-bisect.*detached HEAD" &&
+               test_must_fail git worktree add new-bisect under-bisect &&
+               ! test -d new-bisect
+       )
+'
+
 test_done
index 5043756663eb993db5a93fe1da7149caaca8ac5c..aab4b9552e429692943a2b49cd4c8b7379dab68b 100644 (file)
@@ -234,6 +234,21 @@ static int is_worktree_being_rebased(const struct worktree *wt,
        return found_rebase;
 }
 
+static int is_worktree_being_bisected(const struct worktree *wt,
+                                     const char *target)
+{
+       struct wt_status_state state;
+       int found_rebase;
+
+       memset(&state, 0, sizeof(state));
+       found_rebase = wt_status_check_bisect(wt, &state) &&
+               state.branch &&
+               starts_with(target, "refs/heads/") &&
+               !strcmp(state.branch, target + strlen("refs/heads/"));
+       free(state.branch);
+       return found_rebase;
+}
+
 /*
  * note: this function should be able to detect shared symref even if
  * HEAD is temporarily detached (e.g. in the middle of rebase or
@@ -261,6 +276,10 @@ const struct worktree *find_shared_symref(const char *symref,
                                existing = wt;
                                break;
                        }
+                       if (is_worktree_being_bisected(wt, target)) {
+                               existing = wt;
+                               break;
+                       }
                }
 
                strbuf_reset(&path);