summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Sunshine <sunshine@sunshineco.com>2015-07-17 23:00:10 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-07-20 18:29:51 (GMT)
commitc2842439a3ab9bcab122105f3f457afb37fbc7c1 (patch)
treefd9e02af4b22d4ead36c72253daf171578121759
parent5c942570fe2a48d8fde348e89392c2e9e23aa483 (diff)
downloadgit-c2842439a3ab9bcab122105f3f457afb37fbc7c1.zip
git-c2842439a3ab9bcab122105f3f457afb37fbc7c1.tar.gz
git-c2842439a3ab9bcab122105f3f457afb37fbc7c1.tar.bz2
worktree: make branch creation distinct from worktree population
git-worktree currently conflates branch creation, setting of HEAD in the new worktree, and worktree population into a single sub-invocation of git-checkout, which requires git-checkout to be specially aware that it is operating in a newly-created worktree. The goal is to free git-checkout of that special knowledge, and to do so, git-worktree will eventually perform those operations separately. Thus, as a first step, rather than piggybacking on git-checkout's -b/-B ability to create a new branch at checkout time, make git-worktree responsible for branch creation itself. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/worktree.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/builtin/worktree.c b/builtin/worktree.c
index 83484ad..8225468 100644
--- a/builtin/worktree.c
+++ b/builtin/worktree.c
@@ -314,12 +314,23 @@ static int add(int ac, const char **av, const char *prefix)
opts.new_branch = xstrndup(s, n);
}
+ if (opts.new_branch) {
+ struct child_process cp;
+ memset(&cp, 0, sizeof(cp));
+ cp.git_cmd = 1;
+ argv_array_push(&cp.args, "branch");
+ if (opts.force_new_branch)
+ argv_array_push(&cp.args, "--force");
+ argv_array_push(&cp.args, opts.new_branch);
+ argv_array_push(&cp.args, branch);
+ if (run_command(&cp))
+ return -1;
+ branch = opts.new_branch;
+ }
+
argv_array_push(&cmd, "checkout");
if (opts.force)
argv_array_push(&cmd, "--ignore-other-worktrees");
- if (opts.new_branch)
- argv_array_pushl(&cmd, opts.force_new_branch ? "-B" : "-b",
- opts.new_branch, NULL);
if (opts.detach)
argv_array_push(&cmd, "--detach");
argv_array_push(&cmd, branch);