From d3b9ac07eb44974bb619d71fc6c81c9f2036b96c 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:27 +0700 Subject: worktree.c: make find_shared_symref() return struct worktree * MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gives the caller more information and they can answer things like, "is it the main worktree" or "is it the current worktree". The latter question is needed for the "checkout a rebase branch" case later. Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- branch.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'branch.c') diff --git a/branch.c b/branch.c index 0674a9932..1f1fbf528 100644 --- a/branch.c +++ b/branch.c @@ -336,13 +336,14 @@ void remove_branch_state(void) void die_if_checked_out(const char *branch) { - char *existing; + const struct worktree *wt; - existing = find_shared_symref("HEAD", branch); - if (existing) { - skip_prefix(branch, "refs/heads/", &branch); - die(_("'%s' is already checked out at '%s'"), branch, existing); - } + wt = find_shared_symref("HEAD", branch); + if (!wt) + return; + skip_prefix(branch, "refs/heads/", &branch); + die(_("'%s' is already checked out at '%s'"), + branch, wt->path); } int replace_each_worktree_head_symref(const char *oldref, const char *newref) -- cgit v1.2.1