From: Christian Couder <christian.couder@gmail.com>
To: Jeff King <peff@peff.net>
Cc: git <git@vger.kernel.org>
Subject: Re: Syncing HEAD
Date: Wed, 15 Aug 2018 07:49:25 +0200 [thread overview]
Message-ID: <CAP8UFD3S5vgMSuXfj1z0F7f-9SLVEm6boCHwdNwn7ysvXSRMrA@mail.gmail.com> (raw)
In-Reply-To: <20180814214723.GA667@sigill.intra.peff.net>
On Tue, Aug 14, 2018 at 11:47 PM, Jeff King <peff@peff.net> wrote:
> On Tue, Aug 14, 2018 at 05:06:16PM -0400, Jeff King wrote:
>
>> On Tue, Aug 14, 2018 at 10:09:37PM +0200, Christian Couder wrote:
>>
>> > When cloning with --mirror, the clone gets its HEAD initialized with
>> > the value HEAD has in its origin remote. After that if HEAD changes in
>> > origin there is no simple way to sync HEAD at the same time as the
>> > refs are synced.
>> >
>> > It looks like the simplest way to sync HEAD is:
>> >
>> > 1) git remote show origin
>> > 2) parse "HEAD branch: XXX" from the output of the above command
>> > 3) git symbolic-ref HEAD refs/heads/XXX
>>
>> How about:
>>
>> git remote set-head origin -a
>>
>> ?
>
> Reading your message again, I see you actually care less about the
> refs/remote placeholder and more about the actual HEAD in a bare repo.
Yeah, I am interesting in updating the actual HEAD in a bare repo.
> In which case "git remote" isn't going to help, though its underlying
> code has the algorithm you would want.
Ok, I will take a look at the algorithm.
>> One tricky thing is that the name "refs/remotes/<remote>/HEAD" is only
>> special by convention, and that convention is known on the writing side
>> only by git-clone and git-remote. So obviously:
>
> And so here the convention is simpler, because we're talking about the
> main HEAD. But we still have know if you want to do that, and not update
> some refs/remotes/ symref in a bare repo.
We could maybe look at the "remote.XXX.mirror" config option. If it is
set to "true", we could interpret that as meaning we are interested in
updating the main HEAD and not some refs/remotes/ symref.
> So all of this really implies to me that you want to be able to say
> "take this symref on the other side and update this one on the local
> side". I.e., some way to tell a refspec "don't update the value, update
> the symref destination". So imagine we made "~" the magic character for
> "just the symrefs" (I picked that because it's not allowed in a
> refname).
>
> Then you could do what you want with:
>
> git config --add remote.origin.fetch ~HEAD:HEAD
>
> and these two would be the same:
>
> git remote set-head origin -a
> git fetch origin ~HEAD:refs/remotes/origin/HEAD
>
> And it would allow more exotic things, too, like:
>
> # always update the remote notion of HEAD on every fetch
> git config --add remote.origin.fetch ~HEAD:refs/remotes/origin/HEAD
>
> # update a non-HEAD symref we track for our own purposes
> git fetch origin ~refs/tags/LATEST:refs/tags/LATEST
>
> # or the same thing but using the usual refspec "dst defaults to src"
> # rule and dwim lookup magic
> git fetch origin ~LATEST
And `git fetch origin ~HEAD` would sync the main HEAD?
Yeah, that looks like an interesting solution to the problem.
I wonder though if we should restrict the way `git fetch origin ~XXX`
searches the .git/ directory itself.
> In protocol v0 we don't get symref reports from the other side over the
> git protocol (except for HEAD), but we could use the same logic we use
> for determining HEAD for older versions of Git: find a ref that points
> to the same tip. Though I would say that unlike the existing code in
> guess_remote_head(), we'd probably want to treat an ambiguity as an
> error, and not just default to refs/heads/master.
I wonder what `git fetch origin ~refs/heads/*:refs/heads/*` should do.
Could it know which refs are symrefs using protocol v0? Should it
guess that refs with uppercase names are symrefs? Should we allow '*'
at all in those kinds of refspecs?
It looks like making "~" the magic character for "just the symrefs"
might be a good solution in the end, though we might want to restrict
it to protocol v2.
So perhaps something like `git fetch --update-head` that you suggest
in another email would be a good solution for now and for protocol v0.
next prev parent reply other threads:[~2018-08-15 5:49 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-14 20:09 Syncing HEAD Christian Couder
2018-08-14 20:58 ` Stefan Beller
2018-08-14 21:08 ` Brandon Williams
2018-08-14 21:06 ` Jeff King
2018-08-14 21:47 ` Jeff King
2018-08-15 5:49 ` Christian Couder [this message]
2018-08-17 1:47 ` Jeff King
2018-08-17 16:28 ` Junio C Hamano
2018-08-17 16:48 ` Jeff King
2018-08-14 22:05 ` Ævar Arnfjörð Bjarmason
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=CAP8UFD3S5vgMSuXfj1z0F7f-9SLVEm6boCHwdNwn7ysvXSRMrA@mail.gmail.com \
--to=christian.couder@gmail.com \
--cc=git@vger.kernel.org \
--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.
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).