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

Re: [PATCH v2] ls-remote: add --show-object-format

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 12, 2026, 18:07 UTC
Message-ID
<xmqqfqx5kjoq.fsf@gitster.g>
In-Reply-To
<20261112085205.452463-1-adrian.ratiu@collabora.com>
Adrian Ratiu <adrian.ratiu@collabora.com> writes:
Show 7 quoted lines
> @@ -150,6 +154,9 @@ int cmd_ls_remote(int argc,
>  
>  	if (!dest && !quiet)
>  		fprintf(stderr, "From %s\n", remote->url.v[0]);
> +	if (show_object_format)
> +		printf("object-format: %s\n",
> +		       transport_get_hash_algo(transport)->name);

OK. transport_get_hash_algo() just grabs transport->hash_algo which was relayed from connect.c:get_remote_refs(), so even when talking over an old protocol that does not explicitly declare, we get GIT_HASH_SHA1_LEGACY. IOW, no need to worry about hitting an "eh, we do not know that" here.

Looking good.
Show 36 quoted lines
> +# Run "ls-remote --show-object-format" with the given arguments over
> +# protocol v0 and v2, and check that it prints the object format given
> +# as the first argument, followed by the same refs as plain "ls-remote".
> +test_show_object_format () {
> +	format=$1 &&
> +	shift &&
> +	echo "object-format: $format" >expect &&
> +	git ls-remote "$@" >>expect &&
> +	for version in 0 2
> +	do
> +		git -c protocol.version=$version \
> +			ls-remote --show-object-format "$@" >actual &&
> +		test_cmp expect actual || return 1
> +	done
> +}
> +
> +for hash in sha1 sha256
> +do
> +	test_expect_success "ls-remote --show-object-format with empty $hash remote" '
> +		git init --bare --object-format=$hash empty-$hash.git &&
> +		test_show_object_format $hash empty-$hash.git
> +	'
> +
> +	test_expect_success "ls-remote --show-object-format with $hash remote" '
> +		git init --object-format=$hash repo-$hash &&
> +		test_commit -C repo-$hash one &&
> +		test_show_object_format $hash repo-$hash HEAD
> +	'
> +done
> +
> +test_expect_success 'ls-remote --show-object-format outside repository' '
> +	nongit git init --bare --object-format=sha256 empty-nongit.git &&
> +	echo "object-format: sha256" >expect &&
> +	nongit git ls-remote --show-object-format empty-nongit.git >actual &&
> +	test_cmp expect actual
> +'
And we seem to have adequate test coverage.
Thanks.
Previous: Adrian RatiuNext: Patrick Steinhardt
Message 5 of 6 in “ls-remote: add --show-object-format”
  1. ls-remote: add --show-object-formatAdrian Ratiu, Nov 5, 2026
  2. Patrick SteinhardtNov 5, 2026
  3. Adrian RatiuNov 5, 2026
  4. ls-remote: add --show-object-formatAdrian Ratiu, Nov 12, 2026
  5. Junio C HamanoNov 12, 2026
  6. Patrick SteinhardtNov 13, 2026

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.