From 04a3dfb8b5993fcb807fcbca8ed7ea608d30a204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Fri, 22 Apr 2016 20:01:35 +0700 Subject: worktree.c: check whether branch is bisected in another worktree MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Junio C Hamano --- worktree.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'worktree.c') diff --git a/worktree.c b/worktree.c index 5043756663..aab4b9552e 100644 --- a/worktree.c +++ b/worktree.c @@ -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); -- cgit v1.2.3