git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: New orphan worktree?

From
Eric Sunshine <sunshine@sunshineco.com>
Date
Feb 23, 2021, 00:55 UTC
Message-ID
<CAPig+cQxYtw5z_bRQbS6MLgHQM2OTs5oRfpvKSOwZo8GcuwpTg@mail.gmail.com>
In-Reply-To
<87czwr8wou.fsf@evledraar.gmail.com>

On Mon, Feb 22, 2021 at 7:17 PM Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:

Show 10 quoted lines
> On Tue, Feb 23 2021, Eric Sunshine wrote:
> > I'm not sure I follow. In git-switch, --orphan does not imply -c even
> > though --orphan also creates a new branch (thus seems to work similar
> > to -c); it is nevertheless mutually-exclusive with -c and -C. The same
> > goes for --orphan in git-branch.
>
> I think we're on the same page with regards to what I meant. I.e. I
> don't see how it makes sense to conflate the type of branch we want
> (orphan or not orphan) with whether we want to clobber that branch or
> not (switch -c or -C, or worktree -b or -B)

I see where you're coming from in viewing --orphan as a modifier of branch creation rather than as a branch-creation option itself. However, as far as UI is concerned, that ship sailed a long time ago, I suppose.

Show 17 quoted lines
> > As far as combining --orphan and -C (or -c), I'm not sure how we would
> > arrange that using the existing parse_options() mechanism. It seems
> > too magical and has potential for weird corner cases.
>
> Isn't it just having --orphan be an OPTION_STRING with
> PARSE_OPT_LASTARG_DEFAULT. I.e. to support:
>
>     git switch -b branch --orphan
>     git switch -B branch --orphan
>     git switch --orphan branch
>
> And:
>
>     git worktree add -b branch --orphan
>     git worktree add -B branch --orphan
>
> I didn't test it, just skimmed the code.

I haven't dived into this stuff in a long time, but I'm having trouble convincing myself that it would work out as intended. If I'm reading PARSE_OPT_LASTARG_DEFAULT correctly, `git switch -b <branch> --orphan` would not be the same as `git switch --orphan -b <branch>`, and I don't think it would work at all for git-worktree-add which has additional <path> and <commitish> arguments (i.e. `git worktree add -b <branch> --orphan <path> [<commitish>]`).

Anyhow, as I responded elsewhere to Junio, my present leaning is toward -b, -B, --orphan all being mutually-exclusive branch-creation options, each taking a <branch> argument -- just like they are in git-checkout and git-switch (-c/-C, in this case) -- and allowing --force to overwrite an existing branch (in which case, -B can be viewed as shorthand for `--force -b`).

Show 9 quoted lines
> > Since git-worktree doesn't yet support --orphan, we certainly have
> > more leeway and could go with your proposal of having --orphan be
> > boolean and always requiring it to be used in conjunction with -b/-B.
> > However, I'm quite hesitant to take that approach since it breaks with
> > existing precedent in git-branch and git-switch, in which case
> > --orphan takes its own argument (<branch>) and is mutually-exclusive
> > with -b/-B/-c/-C.
>
> In git-branch? Isn't it only git [checkout|switch] that takes --orphan?

Um, yes, I meant git-checkout everywhere I wrote git-branch. Sorry for the confusion.

> I think not having a -B or -C equivalent at all would be preferrable to
> having a --force special-case just to work around the lack of it for
> --orphan.
I'm having trouble wrapping my brain around this statement.
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 14 of 22 in “New orphan worktree?”
  1. Stefan MonnierJan 6, 2021
  2. Jim HillJan 6, 2021
  3. Elijah NewrenJan 6, 2021
  4. Jim HillJan 6, 2021
  5. Elijah NewrenJan 6, 2021
  6. Eric SunshineJan 6, 2021
  7. Ævar Arnfjörð BjarmasonFeb 18, 2021
  8. Eric SunshineFeb 21, 2021
  9. Ævar Arnfjörð BjarmasonFeb 22, 2021
  10. Eric SunshineFeb 22, 2021
  11. Junio C HamanoFeb 22, 2021
  12. Eric SunshineFeb 23, 2021
  13. Ævar Arnfjörð BjarmasonFeb 23, 2021
  14. Eric SunshineFeb 23, 2021
  15. Ævar Arnfjörð BjarmasonFeb 23, 2021
  16. Junio C HamanoFeb 23, 2021
  17. Junio C HamanoJan 6, 2021
  18. Jim HillJan 6, 2021
  19. Junio C HamanoJan 6, 2021
  20. Jim HillJan 6, 2021
  21. Stefan MonnierJan 6, 2021
  22. Stefan MonnierJan 6, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.