summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorLibravatar Junio C Hamano <gitster@pobox.com>2016-02-24 13:26:00 -0800
committerLibravatar Junio C Hamano <gitster@pobox.com>2016-02-24 13:26:00 -0800
commit595bfefa6c31fa6d76b686ed79b024838db5933e (patch)
tree0fdb54fcd57258da1904bcf11ff608a0184c3a36 /builtin
parentMerge branch 'nd/exclusion-regression-fix' (diff)
parentworktree add -B: do the checkout test before update branch (diff)
downloadtgif-595bfefa6c31fa6d76b686ed79b024838db5933e.tar.xz
Merge branch 'nd/worktree-add-B'
"git worktree add -B <branchname>" did not work. * nd/worktree-add-B: worktree add -B: do the checkout test before update branch worktree: fix "add -B"
Diffstat (limited to 'builtin')
-rw-r--r--builtin/worktree.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 475b9581a5..20cf67a549 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -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);
@@ -336,9 +334,18 @@ static int add(int ac, const char **av, const char *prefix)
branch = ac < 2 ? "HEAD" : av[1];
opts.force_new_branch = !!new_branch_force;
- if (opts.force_new_branch)
+ if (opts.force_new_branch) {
+ struct strbuf symref = STRBUF_INIT;
+
opts.new_branch = new_branch_force;
+ if (!opts.force &&
+ !strbuf_check_branch_ref(&symref, opts.new_branch) &&
+ ref_exists(symref.buf))
+ die_if_checked_out(symref.buf);
+ strbuf_release(&symref);
+ }
+
if (ac < 2 && !opts.new_branch && !opts.detach) {
int n;
const char *s = worktree_basename(path, &n);