git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Björn Steinbrink" <B.Steinbrink@gmx.de>
To: Julian Phillips <julian@quantumfyre.co.uk>
Cc: Daniel Barkalow <barkalow@iabervon.org>,
	James Pickens <jepicken@gmail.com>, Jeff King <peff@peff.net>,
	Junio C Hamano <gitster@pobox.com>,
	Nicolas Pitre <nico@fluxnic.net>,
	Jay Soffian <jaysoffian@gmail.com>,
	git@vger.kernel.org
Subject: Re: [PATCH] Proof-of-concept patch to remember what the detached HEAD was
Date: Sat, 17 Oct 2009 09:55:51 +0200	[thread overview]
Message-ID: <20091017075551.GA5474@atjola.homenet> (raw)
In-Reply-To: <alpine.LNX.2.00.0910161821230.30589@reaper.quantumfyre.co.uk>

On 2009.10.16 18:31:23 +0100, Julian Phillips wrote:
> On Fri, 16 Oct 2009, Bj?rn Steinbrink wrote:
> >On 2009.10.16 13:15:35 +0100, Julian Phillips wrote:
> >>How about:
> >>
> >>$ git checkout origin/master
> >>$ git fetch
> >>Refusing to fetch, as it would update a checkedout branch
> >>"git fetch -f" will force the update, but you will need to run "git
> >>reset --hard HEAD" to update your checkout to match.
> >
> >That would redefine -f (currently means "allow non-fast-forward
> >updates"), the flag that allows the checked out branch head to be
> >updated is -u, --update-head-ok, and is for internal use only.
> >
> >And suggesting "reset --hard" seems wrong, that just kills any
> >uncommitted changes.
> 
> Ok, so the commands were wrong.  Not important.
> 
> It was the approach that I was trying to suggest rather than the
> actual commands.  The point I was trying to make was how, as a user,
> I would be happy to git behave.

Your approach explicitly included "mess up the index/worktree state",
otherwise, "git fetch" would not have to tell the user that he has to do
a "git reset --hard HEAD". I honestly can't believe that you would be
happy with git messing up your work.

> So, I try to run fetch, git says "ooh, now that would be dangerous -
> you can force it happen by running "git foo", but you will then be
> in situation X, which you can then recover from by running "git
> bar", though you may need to run "git stash" to save any edits you
> have made" or something similar.

But why make "git fetch" with non-"obscure" refspecs dangerous to begin
with? If we detach but keep some extra information, there's no need to
make "git fetch" dangerous, _and_ we can still provide a command that
just fetches the most recent version of the "checked out" remote
tracking branch and checks that out. May it be another mode of operation
for "git pull" or some "git up" command or whatever.

> >And such uncommitted changes would be lost in the big "undo the fetch
> >update" diff. So you'd have to do:
> >git reset --soft HEAD@{1}
> >git checkout --merge HEAD@{1}
> >
> >to keep them, while updating to the new state of the remote tracking
> >branch. Not quite intuitive, is it?
> 
> I don't care what git has to do, I'm talking about the user
> experience - if we have to write some new code to support it, that
> really isn't a terribly hard thing to do.  UIs should be driven down
> from the user interaction not up from the implementation.

Those commands are those that git would have to show to you, instead of
"git reset --hard HEAD", i.e. they're what you, as the user, have to do.
And while "git reset --hard HEAD" might be remotely understandable to
the user, that command sequence is very unlikely to be understood by
most. And providing a command that does just this sequence is insane,
it's just a bandaid for git doing crap to your worktree/index state. So
let's better not start with git doing that crap at all.

My current "idea" (I don't think I'll have time to implement that any
time soon) is:

Keep some extra information in HEAD (or somewhere else) when HEAD is
detached about the ref that HEAD is "weakly" bound to. For example, "git
checkout origin/master" might create a weak binding to
refs/remotes/origin/master (for other [corner] cases, see the other
mail I wrote, in which I outlined some cases I considered interesting).

"git update" can use the branch.<name>.{remote,merge} setup, or
alternatively the "weak binding" information, to fetch from the right
remote, and checks whether a fast-forward of HEAD to the according
upstream branch head is possible. If so, it does a "git checkout --merge
<upstream>" (possibly leaving conflicts for the uncommitted changes,
just like "svn update"). If a fast-forward is not possible, it
complains, telling the user that he needs to use "git merge/rebase/pull"
instead, and might want to create a branch head, in case of a detached
HEAD.

If there's also going to be a rule that forbids commits on some kind of
detached HEAD, than the command could also tell the user (when a
fast-forward is not possible) that upstream possibly rewrote history,
and that the user might want to use "git checkout --merge <upstream>"
(or maybe "git update -f"?) to just go to the new upstream version (not
sure if that hint should be shown in addition to or instead of the "git
merge/rebase/pull" hint).

Björn

  parent reply	other threads:[~2009-10-17  7:56 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-14  4:44 [PATCH] Proof-of-concept patch to remember what the detached HEAD was Daniel Barkalow
2009-10-14  5:07 ` Junio C Hamano
2009-10-14  5:08 ` Jeff King
2009-10-14 10:33   ` Johannes Schindelin
2009-10-14 15:39     ` Jeff King
2009-10-14 18:34       ` Junio C Hamano
2009-10-14 18:40         ` Jeff King
2009-10-14 15:56   ` Daniel Barkalow
2009-10-14 18:56 ` Jay Soffian
2009-10-14 19:15   ` Daniel Barkalow
2009-10-14 20:18     ` Nicolas Pitre
2009-10-14 20:37       ` Daniel Barkalow
2009-10-14 20:42       ` Junio C Hamano
2009-10-14 20:48         ` Nicolas Pitre
2009-10-14 22:34           ` Junio C Hamano
2009-10-14 23:09             ` Jeff King
2009-10-14 23:34               ` Nicolas Pitre
2009-10-15  0:56                 ` Junio C Hamano
2009-10-15  1:47                   ` Jeff King
2009-10-15  3:08                     ` Nicolas Pitre
2009-10-15  4:21                       ` Jeff King
2009-10-16  1:04                       ` Johannes Schindelin
2009-10-16  1:36                         ` Nicolas Pitre
2009-10-16  2:07                           ` Johannes Schindelin
2009-10-16  2:45                             ` Nicolas Pitre
2009-10-16  2:56                             ` Junio C Hamano
2009-10-17  7:24                             ` Sean Estabrooks
2009-10-26 22:22                               ` Johannes Schindelin
2009-10-27  3:41                                 ` Nanako Shiraishi
2009-10-27 10:33                                   ` Making Git easy to use -- without RTFM, was " Johannes Schindelin
2009-10-27 17:58                                     ` Avery Pennarun
2009-10-16  0:53                   ` Johannes Schindelin
2009-10-16  3:00                     ` Junio C Hamano
2009-10-15  7:36               ` James Pickens
2009-10-15 12:54                 ` Jakub Narebski
2009-10-15 14:11                   ` Björn Steinbrink
2009-10-15 19:03                   ` Nicolas Pitre
2009-10-15 15:36                 ` Daniel Barkalow
2009-10-15 16:29                   ` Michael J Gruber
2009-10-15 19:07                   ` Nicolas Pitre
2009-10-15 19:22                     ` Daniel Barkalow
2009-10-15 22:56                       ` Thomas Rast
2009-10-15 18:51                 ` Nicolas Pitre
2009-10-15 19:52                   ` Junio C Hamano
2009-10-15 21:26                     ` Jeff King
2009-10-15 21:54                       ` Junio C Hamano
2009-10-15 22:08                         ` Junio C Hamano
2009-10-15 23:16                           ` Nicolas Pitre
2009-10-15 23:47                           ` James Pickens
2009-10-16  0:34                             ` Nicolas Pitre
2009-10-16  0:43                             ` Johannes Schindelin
2009-10-16  5:03                             ` Björn Steinbrink
2009-10-15 22:16                         ` Jeff King
2009-10-15 22:17                           ` Jeff King
2009-10-16  4:29                         ` Björn Steinbrink
2009-10-16  6:02                           ` Daniel Barkalow
2009-10-16  8:27                             ` Björn Steinbrink
2009-10-16 15:44                             ` Nicolas Pitre
2009-10-15 19:31                 ` Daniel Barkalow
2009-10-15 20:34                   ` Junio C Hamano
2009-10-15 21:35                     ` Daniel Barkalow
2009-10-15 21:48                       ` Nicolas Pitre
2009-10-16 12:15                   ` Julian Phillips
2009-10-16 14:30                     ` Björn Steinbrink
2009-10-16 17:31                       ` Julian Phillips
2009-10-16 18:29                         ` Daniel Barkalow
2009-10-16 19:05                         ` Junio C Hamano
2009-10-16 19:48                           ` Julian Phillips
2009-10-16 20:19                             ` Nicolas Pitre
2009-10-17 15:15                               ` Julian Phillips
2009-10-17 17:04                                 ` Björn Steinbrink
2009-10-17 17:35                                   ` Julian Phillips
2009-10-17 17:48                                     ` Björn Steinbrink
2009-10-17 22:28                                       ` Julian Phillips
2009-10-16 20:19                             ` Junio C Hamano
2009-10-17 15:32                               ` Julian Phillips
2009-10-17 17:43                                 ` Junio C Hamano
2009-10-17 22:19                                   ` Julian Phillips
2009-10-17  7:55                         ` Björn Steinbrink [this message]
2009-10-17  8:11                           ` Junio C Hamano
2009-10-17  8:40                             ` Björn Steinbrink
2009-10-17  9:04                               ` Junio C Hamano
2009-10-17 17:07                                 ` James Pickens
2009-10-17 19:41                                 ` Björn Steinbrink
2009-10-18 22:47                                   ` Junio C Hamano
2009-10-19  8:44                                     ` Björn Steinbrink
2009-10-17 15:02                           ` Julian Phillips
2009-10-14 23:52         ` Eric Raible
2009-10-16 22:36 ` Christoph Bartoschek
2009-10-17  7:43   ` Junio C Hamano
2009-10-17  8:19     ` Björn Steinbrink
2009-10-17 17:42       ` Junio C Hamano
2009-10-17 20:35     ` Daniel Barkalow

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=20091017075551.GA5474@atjola.homenet \
    --to=b.steinbrink@gmx.de \
    --cc=barkalow@iabervon.org \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jaysoffian@gmail.com \
    --cc=jepicken@gmail.com \
    --cc=julian@quantumfyre.co.uk \
    --cc=nico@fluxnic.net \
    --cc=peff@peff.net \
    /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).