git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Elijah Newren <newren@gmail.com>,
	Stefan Monnier <monnier@iro.umontreal.ca>,
	Git Mailing List <git@vger.kernel.org>
Subject: Re: New orphan worktree?
Date: Tue, 23 Feb 2021 12:06:08 +0100	[thread overview]
Message-ID: <87a6rv82n3.fsf@evledraar.gmail.com> (raw)
In-Reply-To: <CAPig+cQxYtw5z_bRQbS6MLgHQM2OTs5oRfpvKSOwZo8GcuwpTg@mail.gmail.com>


On Tue, Feb 23 2021, Eric Sunshine wrote:

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

Not really, I think we can have a new-style of it and just say:

    It is also possible to provide `--orphan <branch-name>`, but
    supplying it as an option to `-[cC]` as `-[cC] <branch-name>
    --orphan` is preferred these days.

Whether we should is another matter, see below...

>> > 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>`

Yeah, I think so. But I think for an option like that it would be more
obvious. I.e. we could say:

    If "-b" or "-B" is provided a subsequent "--orphan" is a boolean.

We don't support the combination of the two now, so we could just
mandate that the order matters.

Anyway...

> , 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>]`).

...we can parse these options, whether it's easy or trivial with
parse-options.c is something I'd like to leave aside for now.

Right now I'm not intending to re-roll this patch, but maybe someone
else (or even me) will get to it sometime. I think it's more useful
if/when that happens to get people's take on whether this makes sense as
UI, not whether it's trivial with the current parse_options() API.

I think it's fairly easy to tease this behavior out of
parse_options(). Worse case we can do a pre-loop over argv and see if
both "--orphan" and "-b"/"-B" occur. if so parse it with "--orphan" as a
BOOL, otherwise STRING.

> 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`).

See https://lore.kernel.org/git/7vpqzlrmo4.fsf@alter.siamese.dyndns.org/
for past Junio arguing with his future self :)

I.e. the reason we had -B in the first place is because --force means
something else. We'd need "--force-ref-deletion
--force-work-tree-clobbering" or whatever, or "--force --force".

I like this lower/upper case convention. It started with "branch -D" in
ba65af9c1f6 (git-branch -d <branch>: delete unused branch., 2005-09-14),
but in checkout the --orphan option pre-dates -B. See 9db5ebf4022 (git
checkout: create unparented branch by --orphan, 2010-03-21) and
02ac98374ee (builtin/checkout: learn -B, 2010-06-24).

I don't think we're going to change how "branch -D" and "switch -C" work
at this point, so making things consistent with it makes sense.

>> > 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.

*nod*

>> 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.

I mean I'd rather not have an --orphan mode that works like -B (as
opposed to -b) at all instead of having one that's "--orphan
--force-ref-deletion" or whatever.

It's an obscure enough thing that I don't think anyone *really* cares. I
just wanted to find out if it not being a boolean was intentional, or a
historical accident we would consider fixing if there was further work
on it.

  reply	other threads:[~2021-02-23 11:10 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-06 16:17 New orphan worktree? Stefan Monnier
2021-01-06 17:00 ` Jim Hill
2021-01-06 19:48   ` Elijah Newren
2021-01-06 20:33     ` Jim Hill
2021-01-06 19:40 ` Elijah Newren
2021-01-06 20:01   ` Eric Sunshine
2021-02-18  1:26     ` Ævar Arnfjörð Bjarmason
2021-02-21 19:55       ` Eric Sunshine
2021-02-22  9:44         ` Ævar Arnfjörð Bjarmason
2021-02-22 23:06           ` Eric Sunshine
2021-02-22 23:59             ` Junio C Hamano
2021-02-23  0:33               ` Eric Sunshine
2021-02-23  0:17             ` Ævar Arnfjörð Bjarmason
2021-02-23  0:55               ` Eric Sunshine
2021-02-23 11:06                 ` Ævar Arnfjörð Bjarmason [this message]
2021-02-23 18:14                   ` Junio C Hamano
2021-01-06 21:29   ` Junio C Hamano
2021-01-06 22:01     ` Jim Hill
2021-01-06 22:15       ` Junio C Hamano
2021-01-06 22:25         ` Jim Hill
2021-01-06 22:56           ` Stefan Monnier
2021-01-06 22:01     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87a6rv82n3.fsf@evledraar.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=newren@gmail.com \
    --cc=sunshine@sunshineco.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).