Subject: [bug#49252] [PATCH] Channels defaulting to HEAD instead of ‘master’

From: Kyle Meyer <[email-masked]>
Date: Thu, 08 Jul 2021 20:38:45 -0400

Ludovic Courtès writes:

> For the record, commit cb41c15827a2e910aa56fb5d1917ba8a085c95c7 by Kyle
> (Cc’d) gives the ability to use the remote HEAD by default, which is
> exactly what we need here.
>
> Unfortunately, for the Guix repo at Savannah, I get:
>
> --8<---------------cut here---------------start------------->8---
> $ ./pre-inst-env guix time-machine -- describe
> guix time-machine: error: Git error: reference 'refs/remotes/origin/HEAD' not found
> --8<---------------cut here---------------end--------------->8---
>
> … but it works for <https://github.com/guix-mirror/guix>.
>
> Presumably we have a server-side setup issue at Savannah?

Hmm, it looks like it's there:

  $ git ls-remote https://git.savannah.gnu.org/git/guix.git | grep HEAD
  e499500730de23fd54ae63696a725d4b90a406d7	HEAD

  $ git clone https://git.savannah.gnu.org/git/guix.git && cd guix
  $ git for-each-ref refs/remotes/origin | grep HEAD
  e499500730de23fd54ae63696a725d4b90a406d7 commit	refs/remotes/origin/HEAD
  $ git name-rev refs/remotes/origin/HEAD
  refs/remotes/origin/HEAD master

This might be a long shot, but if you cloned the repo with magit-clone,
it has some custom logic that deletes refs/remotes/<remote>/HEAD unless
magit-clone-set-remote-head is non-nil (and it's nil by default).

> Are there downsides, or cases where it might pick the wrong branch?

The main downside I can think of is what I mentioned in bug#45187
([email-masked]):

  [The remote HEAD symref] probably the best indicator of what the
  primary branch is.  In a clone, it doesn't necessarily match HEAD on
  the remote, because users may change it to another branch they're
  interested in, but that isn't really relevant to these
  behind-the-scenes checkouts.

So, if it's a user-facing clone, refs/remotes/origin/HEAD isn't a
reliable indicator because users are free to redirect the remote HEAD
symref to another branch of interest [*] or to delete it altogether.

I think channel clones would fall into the "behind the scenes" category,
though, right?

[*] This is discussed here:
    https://lore.kernel.org/git/[email-masked]/