Re: [PATCH v3 22/23] worktree: add: auto-vivify new branch when <branch> is omitted
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jul 6, 2015, 19:19 UTC
- Message-ID
- <xmqqpp45ytzh.fsf@gitster.dls.corp.google.com>
- In-Reply-To
- <1436203860-846-23-git-send-email-sunshine@sunshineco.com>
Eric Sunshine <sunshine@sunshineco.com> writes:
Show 10 quoted lines
> diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt > index 377ae0f..da71f50 100644 > --- a/Documentation/git-worktree.txt > +++ b/Documentation/git-worktree.txt > @@ -9,7 +9,7 @@ git-worktree - Manage multiple worktrees > SYNOPSIS > -------- > [verse] > -'git worktree add' [-f] [--detach] [-b <new-branch>] <path> <branch> > +'git worktree add' [-f] [--detach] [-b <new-branch>] <path> [<branch>]
Ahh, OK, this answers my previous question.
Show 6 quoted lines
> + if (ac < 2 && !new_branch && !new_branch_force) {
> + int n;
> + const char *s = worktree_basename(path, &n);
> + new_branch = xstrndup(s, n);
> + }
> +and because this is new_branch, not new_branch_force, we will not accidentally clobber an existing branch. The "hotfix" time is when the end-user tends to be less careful, and it is a good thing to make sure "git worktree add ../hotfix" will not clobber an unrelated "hotfix" branch.
Good.
Which may be something we would want to have a test for, though.
Show 14 quoted lines
> diff --git a/t/t2025-worktree-add.sh b/t/t2025-worktree-add.sh > index 8964dec..8fe242f 100755 > --- a/t/t2025-worktree-add.sh > +++ b/t/t2025-worktree-add.sh > @@ -145,4 +145,9 @@ test_expect_success '"add -b" with <branch> omitted' ' > test_cmp_rev HEAD burble > ' > > +test_expect_success '"add" with <branch> omitted' ' > + git worktree add wiffle/bat && > + test_cmp_rev HEAD bat > +' > + > test_done