git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Taylor Blau <me@ttaylorr.com>
Cc: Matt McCutchen <matt@mattmccutchen.net>, git@vger.kernel.org
Subject: Re: Renaming the "master" branch without breaking existing clones
Date: Mon, 3 Aug 2020 16:45:03 -0400	[thread overview]
Message-ID: <20200803204503.GB2715275@coredump.intra.peff.net> (raw)
In-Reply-To: <20200803194006.GA2715275@coredump.intra.peff.net>

On Mon, Aug 03, 2020 at 03:40:06PM -0400, Jeff King wrote:

> On Mon, Aug 03, 2020 at 12:00:51PM -0400, Taylor Blau wrote:
> 
> > This is more-or-less what I was proposing in the message that I linked
> > above. Maybe a more solidified proposal might look something as follows:
> > 
> >   - We could introduce a mechanism to mark certain refs as aliases to
> >     other refs. For example, a remote might publish its
> >     'refs/heads/master' as an alias to 'refs/heads/main', so that any
> >     reads or writes to the former get applied to the latter
> >     transparently.
> 
> I think symrefs do this already. Try this:

Looks like Junio already mentioned symrefs. I guess I should have read
the whole thread. :)

As he noted, they don't work if you want to free up the original name.
But I think in the master/main renaming case that most people wouldn't
care that much about doing so.

> >   - A ref alias can be annotated to say "I am a transition ref alias",
> >     i.e., that clients should be taught to rename their copy of 'master'
> >     to 'main' (and update remote-tracking refs accordingly).
> 
> It's not specifically marked as a transition, but a client could act on
> the symref advertisement above.

Something like this script could be run on the clients:

  remote=origin
  git ls-remote --symref $remote |
  grep ^ref: |
  while read junk to from; do
    if test "$from" = HEAD; then
      old=$(git symbolic-ref refs/remotes/$remote/HEAD)
      echo "Upstream switched their HEAD:"
      echo "  old: $old"
      echo "  new: $to"
      echo "Update to match?"
      read r </dev/tty
      if test "$r" = yes; then
        git symbolic-ref refs/remotes/$remote/HEAD $to
      fi
    else
      # do we even have the old branch?
      git rev-parse --verify $from >/dev/null 2>&1 || continue
      echo "Upstream is redirecting a branch:"
      echo "     branch: $from"
      echo "  points to: $to"
      echo "And you have a local $from; should we rename it?"
      read r </dev/tty
      if test "$r" = yes; then
        git branch -m ${from#refs/heads/} ${to#refs/heads/}
      fi
    fi
  done

There are probably some rough edges that could be smoothed (only looking
in refs/heads/ and using branch names instead of fully qualified refs,
handling the case that $to already exists more gracefully, better
prompting). But something like that might be useful for projects that
are transitioning.

Note that it only works with protocol v2, though, because we don't
report non-HEAD symrefs in v0.

-Peff

  parent reply	other threads:[~2020-08-03 20:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-03 12:15 Matt McCutchen
2020-08-03 16:00 ` Taylor Blau
2020-08-03 16:19   ` Junio C Hamano
2020-08-03 16:39     ` Taylor Blau
2020-08-03 19:40   ` Jeff King
2020-08-03 20:40     ` Junio C Hamano
2020-08-03 20:45     ` Jeff King [this message]
2020-08-03 21:02       ` Junio C Hamano
2020-08-03 21:11         ` Jeff King
2020-08-03 21:38           ` Junio C Hamano
2020-08-04  0:37     ` Matt McCutchen
2020-08-04  0:43   ` Matt McCutchen
2020-08-03 16:14 ` Junio C Hamano
2020-08-03 17:41   ` Matt McCutchen
2020-08-03 18:20   ` Kaartic Sivaraam
2020-08-03 18:47     ` Junio C Hamano
2020-08-04  8:50       ` Kaartic Sivaraam

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=20200803204503.GB2715275@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=matt@mattmccutchen.net \
    --cc=me@ttaylorr.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 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).