git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: git clone --reference=<repository> (without --dissociate), forgets to copy/get_pack_of objects from <repository> when "--no-local"/"file://" is present

From
Jeff King <peff@peff.net>
Date
Aug 13, 2024, 13:16 UTC
Message-ID
<20240813131614.GF968816@coredump.intra.peff.net>
In-Reply-To
<CANrWfmR2sB8abN3tjuavu-sDwuENMh3DPdFKS9fXan_1kYURPA@mail.gmail.com>
On Tue, Aug 06, 2024 at 09:37:33AM +1200, Han Jiang wrote:
Show 8 quoted lines
> What did you do before the bug happened? (Steps to reproduce your issue)
> 
> (repo7 and repo8 should behave similar to repo5 and repo6, i.e. setup
> ".git/objects/info/alternates" && copy/get_pack_of objects;)
> (repo7 and repo8 shouldn't: forget to copy/get_pack_of objects.)
> (The problem only surfaces after "./client/mirror.git/" is removed:
> repo7 and repo8 should have the original objects (so git log shouldn't
> give error) but they don't have.)

I don't think this expectation is correct. Using "--reference" without "-dissociate" creates a dependency on the mirror repository. It's not safe to delete it. This is discussed in the "--shared" description of git-clone(1), and the "--reference" description refers to it.

So in your example:
> git -C './client' clone --reference='./mirror.git' --no-local '../server/repo.git' './repo7'

I would not expect repo7 to have any objects. Its needs were satisfied by the mirror, and when it told the upload-pack process running in server/repo.git what it had, that process knew that it did not need to send any objects.

It's actually your repo5 and repo6 that are the oddballs:
> git -C './client' clone --reference='./mirror.git' '../server/repo.git' './repo5'

Here since we are cloning a local-file repo, we take a shortcut and do not do any object negotiation at all! Instead, we just take all of the objects from server/repo.git as hardlinks, since doing so is less work than figuring out what we might need.

It makes us robust to mirror.git being removed (since we ended up with duplicates of all of its objects anyway). But it's still not safe in the long run. If the mirror gets new objects, we'd rely on them for subsequent fetches (rather than getting new copies), and the same dependency is created.

-Peff
Previous: Han JiangNext: Han Jiang
Message 2 of 3 in “git clone --reference=<repository> (without --dissociate), forgets to copy/get_pack_of objects from <repository> when "--no-local"/"file://" is present”
  1. Han JiangAug 5, 2024
  2. Jeff KingAug 13, 2024
  3. Han JiangAug 14, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.