Skip to content

Commit

Permalink
worktree: fix "add -B"
Browse files Browse the repository at this point in the history
Current code does not update "symref" when -B is used. This string
contains the new HEAD. Because it's empty "git worktree add -B" fails at
symbolic-ref step.

Because branch creation is already done before calling add_worktree(),
-B is equivalent to -b from add_worktree() point of view. We do not need
the special case for -B.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Feb 15, 2016
1 parent 4943984 commit 0ebf4a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 1 addition & 3 deletions builtin/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ static int add_worktree(const char *path, const char *refname,
die(_("'%s' already exists"), path);

/* is 'refname' a branch or commit? */
if (opts->force_new_branch) /* definitely a branch */
;
else if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&
if (!opts->detach && !strbuf_check_branch_ref(&symref, refname) &&
ref_exists(symref.buf)) { /* it's a branch */
if (!opts->force)
die_if_checked_out(symref.buf);
Expand Down
8 changes: 8 additions & 0 deletions t/t2025-worktree-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,14 @@ test_expect_success '"add" -B/--detach mutually exclusive' '
test_must_fail git worktree add -B poodle --detach bamboo master
'

test_expect_success 'add -B' '
git worktree add -B poodle bamboo2 master^ &&
git -C bamboo2 symbolic-ref HEAD >actual &&
echo refs/heads/poodle >expected &&
test_cmp expected actual &&
test_cmp_rev master^ poodle
'

test_expect_success 'local clone from linked checkout' '
git clone --local here here-clone &&
( cd here-clone && git fsck )
Expand Down

0 comments on commit 0ebf4a2

Please sign in to comment.