git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Thomas Rast <trast@student.ethz.ch>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	<Euguess@gmail.com>, Mikael Magnusson <mikachu@gmail.com>,
	Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>,
	Jeff King <peff@peff.net>, Jay Soffian <jaysoffian@gmail.com>,
	<git@vger.kernel.org>
Subject: Re: [PATCH/RFC] builtin-checkout: suggest creating local branch when appropriate to do so
Date: Tue, 13 Oct 2009 02:24:11 -0700	[thread overview]
Message-ID: <7vy6nfwssk.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: <200910131051.47117.trast@student.ethz.ch> (Thomas Rast's message of "Tue\, 13 Oct 2009 10\:51\:45 +0200")

Thomas Rast <trast@student.ethz.ch> writes:

>> #0. These will stay as is:
>> 
>>  $ git checkout mine               ;# switches to the branch
>>  $ git checkout $any_committish^0  ;# detaches
>> 
>> #1. These used to detach, but will create a local branch
>> 
>>  $ git checkout origin/next        ;# as if with -t
>>  $ git checkout xyzzy/frotz        ;# as if with -t (origin is not special)
>
> Agreed, though I'm still in favour of a cleaner syntax for explicit
> detaching.  (Cleaner in the sense that ^0 is documented as having a
> completely different purpose and only works by accident.)

Oh, ^0 was just one way to make sure a committish is not a refname.  If
you have an abbreviated hexadecimal commit object name, that would also
detach, which should fall into category #0.  Sorry for the omission.

>> #2. These are allowed only when unambiguous and there is no local branch yet.
>> 
>>  $ git checkout next               ;# ok
>>  $ git checkout frotz              ;# ok (origin is not special)
>>  $ git checkout nitfol             ;# not ok (ambiguous and origin is not special)
>
> I'm weakly leaning towards refusing all three, as the user should be
> required to explicitly say a remote branch should be involved.
>
> (Weakly because there's also a certain DWIM advantage to 'git checkout
> sometopic'...)

I thought this was the primary point of what Dscho has been advocating.

>> #3. These used to detach, but what should we do?
>> 
>>  $ git checkout v1.0.0             ;# detach, or refuse???
>
> Refuse, on the grounds that the main goal here is not detaching unless
> specifically told to.  (Having a branch called v1.0.0 is worse, as it
> would just cause a lot of confusion and/or a refusal at the next
> checkout.)
>
>>  $ git checkout origin/master      ;# detach, or refuse???
>
> This seems to be the trickiest of them.  Maybe check out 'master', to
> make the process repeatable.  Imagine, in your setting,
>
>   git checkout origin/next           ;# creates 'next' as with -t
>   git checkout -                     ;# back
>   git checkout origin/next           ;# should go to 'next' again
>
> Then again, that would trade the confusion of detaching for the
> confusion of not checking out the exact commit that the user
> specified.  Worse, 'next' could conceivably be tracking (as per
> branch.next.merge) some entirely different branch, making the "Your
> branch is behind..." message misleading.

As I said already in the thread, I think that is a misguided attempt to
half-hide the fact that there are origin/next (tracking branch) and next
(a fork of it), that are two separate entities.  It is misguided because
the user needs to understand and take advantage of the distinction to do
anything; in other words, it is not even an unnecessary complexity.

So I am very doubtful about the benefit of checking out 'master' when
the user explicitly tells us to check out 'origin/master', only because
the former forked from the latter.

> Some that come to mind:
>
> #3a. Other refs apart from tags that currently detach:
>
>   git fetch origin master            ;# or even sillier, 'git fetch . master'
>   git checkout FETCH_HEAD            ;# used to detach; refuse?

> #3b. Full specifiers that currently detach:
>
>   git checkout refs/heads/master     ;# could eventually attach
>   git checkout heads/master          ;# same

I'd throw both of these into category #3.

Anything that is valid "ref" (i.e. what dwim_ref() groks) that is not
a remote tracking branch (which creates a corresponding local branch)
can refuse to avoid unintended detachment by newbies.

> #0a. Should probably detach if the previous checkout was detached:
>
>   git checkout -                     ;# detach if previous was detached?
>   git checkout @{-1}                 ;# same

Perhaps.

So to recap, "git checkout $token" would:

 * If dwim_ref() groks $token, and

   - if it resolves to refs/heads/*, that is checking out a local branch;

   - if it resolves to refs/remotes/*, and if there is no corresponding
     local branch, create one forked from there, as if -t was given;

   - everything else we used to detach, but we refuse in 1.7.0, to make it
     harder for newbies to detach.

 * If check_ref_format() is happy with $token, get_sha1() does not grok
   $token, and there is only one ref of the form refs/remotes/$o/$token
   then we pretend as if -t $o/$token was given and create a local branch
   $token forked from it.

 * Otherwise, we always detach.

Note that "checkout -" and "checkout @{-4}" are part of dwim_ref() family.

  reply	other threads:[~2009-10-13  9:33 UTC|newest]

Thread overview: 91+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-05 20:46 [PATCH/RFC] builtin-checkout: suggest creating local branch when appropriate to do so Jay Soffian
2009-10-05 21:03 ` Sverre Rabbelier
2009-10-05 21:17 ` Johannes Schindelin
2009-10-05 21:26   ` Sverre Rabbelier
2009-10-05 21:57     ` Jay Soffian
2009-10-05 22:00   ` Jay Soffian
2009-10-05 22:45     ` Johannes Schindelin
2009-10-05 22:56   ` Jeff King
2009-10-06  7:32     ` Thomas Rast
2009-10-06  9:16       ` Johannes Schindelin
2009-10-06 11:36         ` Junio C Hamano
2009-10-06 12:02           ` Johannes Schindelin
2009-10-06 20:09             ` Junio C Hamano
2009-10-06  9:12     ` Johannes Schindelin
2009-10-06  9:28       ` Matthieu Moy
2009-10-06  9:41         ` Mikael Magnusson
2009-10-06 10:04           ` Johannes Schindelin
     [not found]           ` <0016e68fd0123a175304754694b4@google.com>
2009-10-06 16:43             ` Eugene Sajine
2009-10-06 20:33               ` Junio C Hamano
2009-10-12  7:49             ` Johannes Schindelin
2009-10-12 18:36               ` Björn Steinbrink
2009-10-12 21:40               ` Thomas Rast
2009-10-12 22:49                 ` Junio C Hamano
2009-10-13  6:36                   ` Thomas Rast
2009-10-13  7:16                     ` Junio C Hamano
2009-10-13  8:44                       ` Junio C Hamano
2009-10-13  8:51                       ` Thomas Rast
2009-10-13  9:24                         ` Junio C Hamano [this message]
2009-10-13 21:20                           ` Johannes Schindelin
2009-10-13 21:59                             ` Junio C Hamano
2009-10-13 22:06                             ` Jeff King
2009-10-13 23:22                               ` Johannes Schindelin
2009-10-14  1:05                                 ` Jay Soffian
2009-10-14  3:28                                   ` Junio C Hamano
2009-10-14 12:49                                     ` Jay Soffian
2009-10-14 19:31                                       ` Junio C Hamano
2009-10-25 17:44                                     ` Uri Okrent
2009-10-14  4:31                                 ` Jeff King
2009-10-14  9:56                         ` Thomas Rast
2009-10-14 10:46                           ` Jakub Narebski
2009-10-13  9:32                       ` Johannes Sixt
2009-10-13 18:39                       ` Daniel Barkalow
2009-10-13 20:53                         ` Junio C Hamano
2009-10-13 21:31                           ` Daniel Barkalow
2009-10-13 21:57                             ` Jeff King
2009-10-13 22:46                               ` Junio C Hamano
2009-10-13 23:16                                 ` Johannes Schindelin
2009-10-14  9:33                                   ` Thomas Rast
2009-10-16 11:48                                     ` Johannes Schindelin
2009-10-16 12:07                                       ` Thomas Rast
2009-10-25 17:48                                 ` Uri Okrent
2009-10-26  7:14                                   ` Junio C Hamano
2009-10-13 22:38                             ` Björn Steinbrink
2009-10-18  7:58   ` Junio C Hamano
2009-10-18  8:00     ` [PATCH 1/3] check_filename(): make verify_filename() callable without dying Junio C Hamano
2009-10-18  8:01     ` [PATCH 2/3] DWIM "git checkout frotz" to "git checkout -b frotz origin/frotz" Junio C Hamano
2009-10-18 10:34       ` Nanako Shiraishi
2009-10-18 12:00         ` Björn Steinbrink
2009-10-18 20:20           ` Nanako Shiraishi
2009-10-18 22:50             ` Junio C Hamano
2009-10-19  5:58             ` Björn Steinbrink
2009-10-18  8:01     ` [PATCH 3/3] git checkout --nodwim Junio C Hamano
2009-10-18 12:40       ` Alex Riesen
2009-10-18 19:53         ` Junio C Hamano
2009-10-18 21:02           ` [PATCH] Use "--no-" prefix to switch off some of checkout dwimmery Alex Riesen
2009-10-18 22:49             ` Junio C Hamano
2009-10-19  6:07               ` Alex Riesen
2009-10-19  6:12                 ` Alex Riesen
2009-10-19  6:16                   ` Junio C Hamano
2009-10-19  7:17                     ` Alex Riesen
2009-10-19  7:25                       ` Junio C Hamano
2009-10-21 17:29           ` [PATCH 3/3] git checkout --nodwim Avery Pennarun
2009-10-21 21:21             ` Nanako Shiraishi
2009-10-21 22:14               ` Junio C Hamano
2009-10-21 22:35                 ` [PATCH] git checkout --no-guess Junio C Hamano
2009-10-21 22:51                   ` Avery Pennarun
2009-10-26 18:17                     ` Jay Soffian
2009-10-26 18:25                       ` Avery Pennarun
2009-10-22  0:27               ` [PATCH 3/3] git checkout --nodwim Johannes Schindelin
2009-10-22  7:09                 ` Erik Faye-Lund
2009-10-23  8:57                 ` Michael J Gruber
2009-10-24  6:35                 ` Junio C Hamano
2009-10-24 14:59                   ` David Roundy
2009-10-24 19:25                     ` Junio C Hamano
2009-10-26 20:12                     ` Johannes Schindelin
2009-10-26 20:40                       ` Avery Pennarun
2009-10-26 21:26                         ` Jeff King
2009-10-26 22:01                           ` Avery Pennarun
2009-10-26 22:14                             ` Jeff King
2009-10-26 22:28                               ` Avery Pennarun
2009-10-05 22:52 ` [PATCH/RFC] builtin-checkout: suggest creating local branch when appropriate to do so Jeff King

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

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

  git send-email \
    --in-reply-to=7vy6nfwssk.fsf@alter.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=Euguess@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=git@vger.kernel.org \
    --cc=jaysoffian@gmail.com \
    --cc=mikachu@gmail.com \
    --cc=peff@peff.net \
    --cc=trast@student.ethz.ch \
    /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.
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 NNTP newsgroup(s).