git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Best way to update `HEAD` in mirrored repos
@ 2022-06-08 20:36 Rodrigo Silva Mendoza
  2022-06-08 22:53 ` Junio C Hamano
  2022-06-09  8:02 ` Johannes Schindelin
  0 siblings, 2 replies; 9+ messages in thread
From: Rodrigo Silva Mendoza @ 2022-06-08 20:36 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-06-15  4:19 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 20:36 Best way to update `HEAD` in mirrored repos Rodrigo Silva Mendoza
2022-06-08 22:53 ` 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

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).