git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Rodrigo Silva Mendoza <rodrigosilvamendoza3@gmail.com>
To: git@vger.kernel.org
Subject: Best way to update `HEAD` in mirrored repos
Date: Wed, 8 Jun 2022 13:36:02 -0700	[thread overview]
Message-ID: <CANWRddN4R6AceeaOyZm1vs8AXBNv3J+cE5MOyrhKVhcqddjUOA@mail.gmail.com> (raw)

Hi all,

Given a repo cloned like so:
`git clone --mirror someRemote`

And then with its origin updated like so
`git remote set-url origin someRemote`

What would be the best way to update the `HEAD` ref in the clone, if
some change happens to the remote HEAD? Like say, the default branch
changing from `main` to `dev` or being renamed from `main` to
`main_2`.

What I've got that I think works
1. Get the ref from the origin that points to `HEAD`. Extract the ref
from the output.
2. Manually update the `HEAD` ref with the extracted output prior step

Like so:
```
$ git ls-remote --symref origin HEAD
ref: refs/heads/good_main_3     HEAD
0666a519f94b8500ab6f14bdf7c9c2e5ca7d5821        HEAD

$ git symbolic-ref HEAD refs/heads/good_main_3
```

Does this make sense?

The following are some of the things I've tried - they all fail to
update the `HEAD` file, or fail for some other reason.
`git fetch -p`
`git fetch -p -a`
`get fetch -p -a -u`
`git remote set-head origin -a`
   Fails with "error: Not a valid ref:
refs/remotes/origin/good_main_3". The ref it fails with is whatever
the remote HEAD is.
`git remote update --prune`

And my use case:
I have a set of git repos cloned/mirrored. They are then indexed for
search, using the `HEAD` ref. The indexer runs periodically, and
before indexing it always runs `get fetch -p` to update repos. For
each repo, to get the latest commit to index, I use the libgit2
equivalent of `git rev-parse HEAD^0`. Right now, previously cloned
repos whose HEAD is updated after the initial clone will fail at this
step, which causes them to not get indexed. Here's an example run, all
for the same repo `x`.

1. `git clone & set origin for repo x` (indexer first clones repo if
it doesn't exist)
2. `git rev-parse HEAD^0` - successfully outputs some commit sha
3. Github default branch is renamed from `main` to `main_3`
4. `git fetch -p` - indexer runs this to update
5. `git rev-parse HEAD^0` - now outputs "fatal: ambiguous argument
'HEAD^0': unknown revision or path not in the working tree."

Thanks for your time,

Rodrigo

             reply	other threads:[~2022-06-08 20:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 20:36 Rodrigo Silva Mendoza [this message]
2022-06-08 22:53 ` Best way to update `HEAD` in mirrored repos Junio C Hamano
2022-06-09  5:01   ` Rodrigo Silva Mendoza
2022-06-09  8:02 ` Johannes Schindelin
2022-06-09 14:46   ` Rodrigo Silva Mendoza
2022-06-10 21:46     ` Johannes Schindelin
2022-06-10 21:53       ` Junio C Hamano
2022-06-15  4:11         ` Rodrigo Silva Mendoza
2022-06-15  4:18           ` Rodrigo Silva Mendoza

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=CANWRddN4R6AceeaOyZm1vs8AXBNv3J+cE5MOyrhKVhcqddjUOA@mail.gmail.com \
    --to=rodrigosilvamendoza3@gmail.com \
    --cc=git@vger.kernel.org \
    /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).