Subject: Re: git clone of empty repositories doesn't preserve hash

From: Junio C Hamano <[email-masked]>
Date: Tue, 25 Apr 2023 16:12:15 -0700

"brian m. carlson" <[email-masked]> writes:

> If nobody looks at this, I'll take a look tomorrow and hopefully send a
> patch.  I just wanted to point this out to the list right away in the
> interest of getting it noticed.

Thanks.  

The topic in question has been in 'master' for 2 weeks, since it was
merged at 96f4113a (Merge branch 'jc/clone-object-format-from-void',
2023-04-11), and as I said, what your test demonstrates is not a
regression caused by the topic but "was broken, did not get
addressed, is still broken".  So it does not sound like it needs
"right away" kind of attention.

> +test_expect_success 'clone propagates object-format from empty repo' '
> +	test_when_finished "rm -fr src256 dst256" &&
> +
> +	echo sha256 >expect &&
> +	git init --object-format=sha256 src256 &&
> +	git clone src256 dst256 &&

This needs to be at least "git clone --no-local" for it to be v0/v1
protocol test.  It is testing the local optimization codepath.

We could peek the original repository and copy the hash function
name to the target as part of the local cloning.  That obviously
is outside the scope of the earlier fix that worked only at the
protocol level.

And I think even with "--no-local" to make it about v0/v1 protocol,
the outcome is still pretty much expected.  If we make the above
command line to

	GIT_TRACE_PACKET=1 \
	git clone --no-local src256 dst256 &&

to clone over the on-the-wire protocol, then we see

    Cloning into 'dst256'...
    packet:  upload-pack> 0000
    packet:        clone< 0000
    warning: You appear to have cloned an empty repository.
    packet:        clone> 0000
    packet:  upload-pack< 0000
    --- expect      2023-04-25 22:55:39.771850195 +0000
    ...

in the output of "sh t5700-*.sh -i -v".  Without any ref, v0/v1 can
not carry any capabilities, because there is no ref information to
tuck the capabilities on.

I unfortunately doubt that any solution would exist that does not
break compatibility with the deployed clients that expect the
current v0/v1.

Thanks.