From: Duy Nguyen <pclouds@gmail.com>
To: Kirill Likhodedov <kirill.likhodedov@jetbrains.com>
Cc: git <git@vger.kernel.org>, Eric Sunshine <sunshine@sunshineco.com>
Subject: Re: git worktree fails to recreate existing branch even with -B
Date: Mon, 15 Feb 2016 16:41:54 +0700 [thread overview]
Message-ID: <20160215094154.GA11698@lanh> (raw)
In-Reply-To: <344AE670-BF9A-4779-AFB0-50B870E1D488@jetbrains.com>
On Tue, Feb 09, 2016 at 05:54:01PM +0300, Kirill Likhodedov wrote:
> Git doesn’t allow me to execute
> git worktree add -B <branch> <path> <start-point>
> where <branch> already exists in the repository.
>
> The command prints the following:
> Preparing <path> (identifier <branch>)
> fatal: Refusing to point HEAD outside of refs/
>
> I’m trying to create a worktree on an existing branch <branch>,
> which should point to <start-point>. This obviously should fail with
> “-b”, but I use “-B” and expect it to be reset to <start-point> as
> mentioned in the docs:
>
> By default, -b refuses to create a new branch if it already exists.
> -B overrides this safeguard, resetting <new-branch> to <branch>.
>
> Do I miss something or there is a bug?
According to the man page, this looks like a bug.
> Steps to reproduce:
>
> git init wt
> cd wt
> echo 'asd' > a.txt ; git add a.txt ; git commit -m initial
> git branch br1
> git worktree add -B br1 ~/temp/br1 master
>
> Error message:
> Preparing /Users/loki/temp/br1 (identifier br1)
> fatal: Refusing to point HEAD outside of refs/
GIT_TRACE=2 gives me
trace: built-in: git 'symbolic-ref' 'HEAD' ''
fatal: Refusing to point HEAD outside of refs/
So we pass wrong argument to symbolic-ref. The '' should be
'refs/heads/br1'. This patch seems to fix it.
-- 8< --
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 475b958..d5b319f 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -202,7 +202,7 @@ static int add_worktree(const char *path, const char *refname,
/* is 'refname' a branch or commit? */
if (opts->force_new_branch) /* definitely a branch */
- ;
+ strbuf_addf(&symref, "refs/heads/%s", refname);
else if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&
ref_exists(symref.buf)) { /* it's a branch */
if (!opts->force)
-- 8< --
--
Duy
next prev parent reply other threads:[~2016-02-15 9:41 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-09 14:54 git worktree fails to recreate existing branch even with -B Kirill Likhodedov
2016-02-15 9:41 ` Duy Nguyen [this message]
2016-02-15 13:35 ` [PATCH 1/2] worktree: fix "add -B" Nguyễn Thái Ngọc Duy
2016-02-15 13:35 ` [PATCH 2/2] worktree add -B: do the checkout test before update branch Nguyễn Thái Ngọc Duy
2016-02-15 23:53 ` [PATCH 1/2] worktree: fix "add -B" Junio C Hamano
2016-02-16 1:15 ` Duy Nguyen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160215094154.GA11698@lanh \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=kirill.likhodedov@jetbrains.com \
--cc=sunshine@sunshineco.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).