mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
worktree: simplify new branch (-b/-B) option checking
Make 'new_branch' be the name of the new branch for both forced and non-forced cases; and add boolean 'force_new_branch' to indicate forced branch creation. This will simplify logic later on when git-worktree handles branch creation locally rather than delegating it to git-checkout as part of the worktree population phase. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
cd2f471311
commit
eef005dcb3
|
@ -272,7 +272,7 @@ static int add_worktree(const char *path, const char **child_argv)
|
||||||
|
|
||||||
static int add(int ac, const char **av, const char *prefix)
|
static int add(int ac, const char **av, const char *prefix)
|
||||||
{
|
{
|
||||||
int force = 0, detach = 0;
|
int force = 0, detach = 0, force_new_branch;
|
||||||
const char *new_branch = NULL, *new_branch_force = NULL;
|
const char *new_branch = NULL, *new_branch_force = NULL;
|
||||||
const char *path, *branch;
|
const char *path, *branch;
|
||||||
struct argv_array cmd = ARGV_ARRAY_INIT;
|
struct argv_array cmd = ARGV_ARRAY_INIT;
|
||||||
|
@ -295,7 +295,11 @@ static int add(int ac, const char **av, const char *prefix)
|
||||||
path = prefix ? prefix_filename(prefix, strlen(prefix), av[0]) : av[0];
|
path = prefix ? prefix_filename(prefix, strlen(prefix), av[0]) : av[0];
|
||||||
branch = ac < 2 ? "HEAD" : av[1];
|
branch = ac < 2 ? "HEAD" : av[1];
|
||||||
|
|
||||||
if (ac < 2 && !new_branch && !new_branch_force) {
|
force_new_branch = !!new_branch_force;
|
||||||
|
if (force_new_branch)
|
||||||
|
new_branch = new_branch_force;
|
||||||
|
|
||||||
|
if (ac < 2 && !new_branch) {
|
||||||
int n;
|
int n;
|
||||||
const char *s = worktree_basename(path, &n);
|
const char *s = worktree_basename(path, &n);
|
||||||
new_branch = xstrndup(s, n);
|
new_branch = xstrndup(s, n);
|
||||||
|
@ -305,9 +309,8 @@ static int add(int ac, const char **av, const char *prefix)
|
||||||
if (force)
|
if (force)
|
||||||
argv_array_push(&cmd, "--ignore-other-worktrees");
|
argv_array_push(&cmd, "--ignore-other-worktrees");
|
||||||
if (new_branch)
|
if (new_branch)
|
||||||
argv_array_pushl(&cmd, "-b", new_branch, NULL);
|
argv_array_pushl(&cmd, force_new_branch ? "-B" : "-b",
|
||||||
if (new_branch_force)
|
new_branch, NULL);
|
||||||
argv_array_pushl(&cmd, "-B", new_branch_force, NULL);
|
|
||||||
if (detach)
|
if (detach)
|
||||||
argv_array_push(&cmd, "--detach");
|
argv_array_push(&cmd, "--detach");
|
||||||
argv_array_push(&cmd, branch);
|
argv_array_push(&cmd, branch);
|
||||||
|
|
Loading…
Reference in a new issue