mbox series

[v8,0/4] worktree: Support `--orphan` when creating new worktrees

Message ID 20230109173227.29264-1-jacobabel@nullpo.dev (mailing list archive)
Headers show
Series worktree: Support `--orphan` when creating new worktrees | expand

Message

Jacob Abel Jan. 9, 2023, 5:32 p.m. UTC
While working with the worktree based git workflow, I realised that setting
up a new git repository required switching between the traditional and
worktree based workflows. Searching online I found a SO answer [1] which
seemed to support this and which indicated that adding support for this should
not be technically difficult.

This patchset has four parts:
  * adding `-B` to the usage docs (noticed during dev and it seemed too small
    to justify a separate submission)
  * adding a helper fn to simplify testing for mutual exclusion of options
    in `t/t2400-worktree-add.sh`
  * adding orphan branch functionality (as is present in `git-switch`)
    to `git-worktree-add`
  * adding an advise for using --orphan when `git worktree add` fails due to
    a bad ref.

Changes from v7:
  * Changed test_wt_add_excl() to use `grep -E` instead of `grep -P` (2/4) [2][3].

1. https://stackoverflow.com/a/68717229/15064705/
2. https://lore.kernel.org/git/xmqq7cxxzefp.fsf@gitster.g/
3. https://lore.kernel.org/git/230109.86r0w328nu.gmgdl@evledraar.gmail.com/

Jacob Abel (4):
  worktree add: include -B in usage docs
  worktree add: refactor opt exclusion tests
  worktree add: add --orphan flag
  worktree add: add hint to direct users towards --orphan

 Documentation/config/advice.txt |  4 ++
 Documentation/git-worktree.txt  | 17 +++++-
 advice.c                        |  1 +
 advice.h                        |  1 +
 builtin/worktree.c              | 65 ++++++++++++++++++++---
 t/t2400-worktree-add.sh         | 94 +++++++++++++++++++++++++++++----
 6 files changed, 164 insertions(+), 18 deletions(-)

Range-diff against v7:
1:  a9ef3eca7b = 1:  a9ef3eca7b worktree add: include -B in usage docs
2:  d124cc481c ! 2:  4b447a597c worktree add: refactor opt exclusion tests
    @@ t/t2400-worktree-add.sh: test_expect_success '"add" no auto-vivify with --detach
     +	local opts="$*" &&
     +	test_expect_success "'worktree add' with '$opts' has mutually exclusive options" '
     +		test_must_fail git worktree add $opts 2>actual &&
    -+		grep -P "fatal:( options)? .* cannot be used together" actual
    ++		grep -E "fatal:( options)? .* cannot be used together" actual
     +	'
     +}

3:  b66ea4d309 = 3:  7574f425f4 worktree add: add --orphan flag
4:  b779606121 = 4:  31ae93ba7a worktree add: add hint to direct users towards --orphan
--
2.38.2

Comments

Ævar Arnfjörð Bjarmason Jan. 9, 2023, 7:20 p.m. UTC | #1
On Mon, Jan 09 2023, Jacob Abel wrote:

> While working with the worktree based git workflow, I realised that setting
> up a new git repository required switching between the traditional and
> worktree based workflows. Searching online I found a SO answer [1] which
> seemed to support this and which indicated that adding support for this should
> not be technically difficult.
>
> This patchset has four parts:
>   * adding `-B` to the usage docs (noticed during dev and it seemed too small
>     to justify a separate submission)
>   * adding a helper fn to simplify testing for mutual exclusion of options
>     in `t/t2400-worktree-add.sh`
>   * adding orphan branch functionality (as is present in `git-switch`)
>     to `git-worktree-add`
>   * adding an advise for using --orphan when `git worktree add` fails due to
>     a bad ref.
>
> Changes from v7:
>   * Changed test_wt_add_excl() to use `grep -E` instead of `grep -P` (2/4) [2][3].
>
> 1. https://stackoverflow.com/a/68717229/15064705/
> 2. https://lore.kernel.org/git/xmqq7cxxzefp.fsf@gitster.g/
> 3. https://lore.kernel.org/git/230109.86r0w328nu.gmgdl@evledraar.gmail.com/

I've looked this & previous iterations over carefully, and this now
looks good to me. Thanks for sticking with this so long.

For what it's worth (if Junio would like to add it):

Reviewed-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Junio C Hamano Jan. 13, 2023, 5:34 p.m. UTC | #2
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:

> I've looked this & previous iterations over carefully, and this now
> looks good to me. Thanks for sticking with this so long.
>
> For what it's worth (if Junio would like to add it):
>
> Reviewed-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>

Thanks, but Phillip's point of -B/-b deserves consideration, I would
say.  It seems that the required change is just a syntax sugar
without having to change anything deeper?