git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: "Ævar Arnfjörð Bjarmason" <avarab@gmail.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: Mon, 22 Feb 2021 18:06:32 -0500	[thread overview]
Message-ID: <CAPig+cSkL+5otKUWwm=CLaRR+j71wW61U7LWtmuUHO+7bZaY_g@mail.gmail.com> (raw)
In-Reply-To: <87ft1o8mi0.fsf@evledraar.gmail.com>

On Mon, Feb 22, 2021 at 4:45 AM Ævar Arnfjörð Bjarmason
<avarab@gmail.com> wrote:
> On Sun, Feb 21 2021, Eric Sunshine wrote:
> > Rather than making --orphan a boolean flag, we'd probably want to
> > mirror the behavior of the other commands and have <branch> be an
> > argument consumed by --orphan:
> >
> >     git worktree add --orphan <branch> <path>
> >
> > That would make --orphan, -b, and -B mutually exclusive, much like
> > they are for git-checkout, and much like -c, -C, and --orphan are
> > mutually exclusive for git-switch.
>
> I see now (but didn't before, I haven't really used "switch" before)
> that that's how it works.
>
> But that doesn't seem to make much sense as a UI, maybe I'm missing
> something but how do you:
>
>     git switch --orphan existing-branch
>
> Just like you can:
>
>     git switch -C existing-branch <start-point>

When responding to your initial email, I noticed this same shortcoming
of --orphan in both git-branch and git-switch, and assumed that's why
you made it a boolean in combination with -b/-B in "git worktree add".
Before writing that email, I did put a bit of thought into how one
might support a "force" mode but didn't include my thoughts in the
message.

> It's actually this exact use-case that prompted me to write the --orphan
> patch. I wanted to create a "meta" orphan branch in my git.git, but had
> an existing local "meta" (from Jeff King) that I'd happened to have
> checked out long ago which I first needed to "git branch -D".
>
> Wouldn't it make more sense for a feature like this & back-compat to
> start with switch's "--orphan" implying "-c", but you could also supply
> "--orphan -C" instead? And in worktree have -b and -B work like they do
> for other branches.

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.

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.

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.

When I was pondering the issue before writing my original response,
two thoughts came to mind. (1) "git worktree add --force --orphan
<branch>" would be one way to make your case work; (2) given how
infrequently --orphan is used, we just punt and require people to
first use "git branch -D <branch>" if necessary (which has been the
status-quo for git-branch and git-switch). The latter thought is
superficially tempting, though it doesn't help in automation
situations since "git branch -D <branch>" errors out if <branch>
doesn't exist, so a script would first have to check for existence of
<branch> before attempting to delete it prior to using "git worktree
add --orphan <branch>".

So, I don't have any great answers at this time.

  reply	other threads:[~2021-02-22 23:09 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 [this message]
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
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='CAPig+cSkL+5otKUWwm=CLaRR+j71wW61U7LWtmuUHO+7bZaY_g@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=monnier@iro.umontreal.ca \
    --cc=newren@gmail.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).