{"thread":{"id":"66782","subject":"[PATCH] ls-remote: add --show-object-format","startedAt":"2026-11-05T10:45:41Z","lastAt":"2026-11-13T07:27:19Z","messageCount":6,"participants":["Adrian Ratiu","Patrick Steinhardt","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"557537","messageId":"20261105104541.790881-1-adrian.ratiu@collabora.com","threadId":"66782","inReplyTo":null,"subject":"[PATCH] ls-remote: add --show-object-format","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-05T10:45:41Z","receivedAt":"2026-11-05T10:45:41Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"While working on JJ sha256 remote support (it uses Git for networking),\nI noticed there is no way to get the object format of a repo without\ncloning it. [1]\n\nGit clone learns the remote format during the protocol handshake, but\nit is not shown anywhere else. For example, when creating an empty repo\nand running \"git fetch\":\n\n1. If the remote has references, fetch can fail with a mismatch error\nand \"git ls-remote\" shows the format indirectly through the length\nof the object IDs. Not ideal, but the it can be figured out eventually.\n\n2. If the remote is empty, \"git ls-remote\" prints nothing and fetch\nsucceeds, so the new local repo can silently get the wrong format,\nwhich only shows up later, on the first push.\n\nTo fill this gap, add a ls-remote --show-object-format option which\nprints the object format learned from the remote on a line of its own,\nbefore the references.\n\n[1]: https://github.com/jj-vcs/jj/issues/3813\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\n Documentation/git-ls-remote.adoc | 10 ++++++-\n builtin/ls-remote.c              |  8 +++++-\n t/t5512-ls-remote.sh             | 46 ++++++++++++++++++++++++++++++++\n 3 files changed, 62 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-ls-remote.adoc b/Documentation/git-ls-remote.adoc\nindex d71c4ab3e2..1abf7b60b7 100644\n--- a/Documentation/git-ls-remote.adoc\n+++ b/Documentation/git-ls-remote.adoc\n@@ -11,7 +11,8 @@ SYNOPSIS\n [verse]\n 'git ls-remote' [--branches] [--tags] [--refs] [--upload-pack=<exec>]\n \t      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]\n-\t      [--symref] [<repository> [<patterns>...]]\n+\t      [--symref] [--show-object-format]\n+\t      [<repository> [<patterns>...]]\n \n DESCRIPTION\n -----------\n@@ -64,6 +65,13 @@ OPTIONS\n \tupload-pack only shows the symref HEAD, so it will be the only\n \tone shown by ls-remote.\n \n+--show-object-format::\n+\tShow the object format (hash algorithm, e.g. `sha1` or `sha256`) used\n+\tby the remote repository before printing the references, on a line of\n+\tits own. This also works for a remote repo without any refs, which is\n+\tuseful to find out which object format to use for a local repository,\n+\tbefore pushing or fetching the new remote.\n+\n --sort=<key>::\n \tSort based on the key given. Prefix `-` to sort in descending order\n \tof the value. Supports \"version:refname\" or \"v:refname\" (tag names\ndiff --git a/builtin/ls-remote.c b/builtin/ls-remote.c\nindex fe77829557..6d961f9961 100644\n--- a/builtin/ls-remote.c\n+++ b/builtin/ls-remote.c\n@@ -12,7 +12,8 @@\n static const char * const ls_remote_usage[] = {\n \tN_(\"git ls-remote [--branches] [--tags] [--refs] [--upload-pack=<exec>]\\n\"\n \t   \"              [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]\\n\"\n-\t   \"              [--symref] [<repository> [<patterns>...]]\"),\n+\t   \"              [--symref] [--show-object-format]\\n\"\n+\t   \"              [<repository> [<patterns>...]]\"),\n \tNULL\n };\n \n@@ -49,6 +50,7 @@ int cmd_ls_remote(int argc,\n \tint quiet = 0;\n \tint status = 0;\n \tint show_symref_target = 0;\n+\tint show_object_format = 0;\n \tconst char *uploadpack = NULL;\n \tstruct strvec pattern = STRVEC_INIT;\n \tstruct transport_ls_refs_options transport_options =\n@@ -89,6 +91,8 @@ int cmd_ls_remote(int argc,\n \t\t\t      2, PARSE_OPT_NOCOMPLETE),\n \t\tOPT_BOOL(0, \"symref\", &show_symref_target,\n \t\t\t N_(\"show underlying ref in addition to the object pointed by it\")),\n+\t\tOPT_BOOL(0, \"show-object-format\", &show_object_format,\n+\t\t\t N_(\"show the object format used by the remote repository\")),\n \t\tOPT_STRING_LIST('o', \"server-option\", &server_options, N_(\"server-specific\"), N_(\"option to transmit\")),\n \t\tOPT_END()\n \t};\n@@ -150,6 +154,8 @@ int cmd_ls_remote(int argc,\n \n \tif (!dest && !quiet)\n \t\tfprintf(stderr, \"From %s\\n\", remote->url.v[0]);\n+\tif (show_object_format)\n+\t\tprintf(\"%s\\n\", transport_get_hash_algo(transport)->name);\n \tfor ( ; ref; ref = ref->next) {\n \t\tstruct ref_array_item *item;\n \t\tif (!check_ref_type(ref, flags))\ndiff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh\nindex 2e1d4f7586..7e82154fe4 100755\n--- a/t/t5512-ls-remote.sh\n+++ b/t/t5512-ls-remote.sh\n@@ -332,6 +332,52 @@ test_expect_success 'indicate no refs in v0 standards-compliant empty remote' '\n \ttest_expect_code 2 git ls-remote --exit-code --upload-pack=./cat-input .\n '\n \n+# Run \"ls-remote --show-object-format\" with the given arguments over\n+# protocol v0 and v2, and compare its output with \"expect\".\n+test_show_object_format () {\n+\tfor version in 0 2\n+\tdo\n+\t\tgit -c protocol.version=$version \\\n+\t\t\tls-remote --show-object-format \"$@\" >actual &&\n+\t\ttest_cmp expect actual || return 1\n+\tdone\n+}\n+\n+test_expect_success 'ls-remote --show-object-format with empty sha1 remote' '\n+\tgit init --bare --object-format=sha1 empty-sha1.git &&\n+\techo sha1 >expect &&\n+\ttest_show_object_format empty-sha1.git\n+'\n+\n+test_expect_success 'ls-remote --show-object-format with empty sha256 remote' '\n+\tgit init --bare --object-format=sha256 empty-sha256.git &&\n+\techo sha256 >expect &&\n+\ttest_show_object_format empty-sha256.git\n+'\n+\n+test_expect_success 'ls-remote --show-object-format with sha1 remote' '\n+\tgit init --object-format=sha1 repo-sha1 &&\n+\ttest_commit -C repo-sha1 one &&\n+\toid=$(git -C repo-sha1 rev-parse HEAD) &&\n+\tprintf \"sha1\\n%s\\tHEAD\\n\" \"$oid\" >expect &&\n+\ttest_show_object_format repo-sha1 HEAD\n+'\n+\n+test_expect_success 'ls-remote --show-object-format with sha256 remote' '\n+\tgit init --object-format=sha256 repo-sha256 &&\n+\ttest_commit -C repo-sha256 one &&\n+\toid=$(git -C repo-sha256 rev-parse HEAD) &&\n+\tprintf \"sha256\\n%s\\tHEAD\\n\" \"$oid\" >expect &&\n+\ttest_show_object_format repo-sha256 HEAD\n+'\n+\n+test_expect_success 'ls-remote --show-object-format outside repository' '\n+\tnongit git init --bare --object-format=sha256 empty-nongit.git &&\n+\techo sha256 >expect &&\n+\tnongit git ls-remote --show-object-format empty-nongit.git >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'ls-remote works outside repository' '\n \t# It is important for this repo to be inside the nongit\n \t# area, as we want a repo name that does not include\n-- \n2.56.0\n\n\n"},{"id":"557549","messageId":"auyO7lmLKD2OSwnD@pks.im","threadId":"66782","inReplyTo":"20261105104541.790881-1-adrian.ratiu@collabora.com","subject":"Re: [PATCH] ls-remote: add --show-object-format","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-05T14:13:02Z","receivedAt":"2026-11-05T14:13:02Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 05, 2026 at 12:45:41PM +0200, Adrian Ratiu wrote:\n> While working on JJ sha256 remote support (it uses Git for networking),\n> I noticed there is no way to get the object format of a repo without\n> cloning it. [1]\n> \n> Git clone learns the remote format during the protocol handshake, but\n> it is not shown anywhere else. For example, when creating an empty repo\n> and running \"git fetch\":\n> \n> 1. If the remote has references, fetch can fail with a mismatch error\n> and \"git ls-remote\" shows the format indirectly through the length\n> of the object IDs. Not ideal, but the it can be figured out eventually.\n\ns/the it/then it/\n\nAlso, this is a somewhat imperfect way to detect the hash algorithm as\nit assumes that we don't ever add a third hash that has the same length\nas either of the existing ones. So it works now, but it may not work in\nthe future anymore.\n\n> 2. If the remote is empty, \"git ls-remote\" prints nothing and fetch\n> succeeds, so the new local repo can silently get the wrong format,\n> which only shows up later, on the first push.\n> \n> To fill this gap, add a ls-remote --show-object-format option which\n> prints the object format learned from the remote on a line of its own,\n> before the references.\n\nSeems sensible.\n\n> diff --git a/Documentation/git-ls-remote.adoc b/Documentation/git-ls-remote.adoc\n> index d71c4ab3e2..1abf7b60b7 100644\n> --- a/Documentation/git-ls-remote.adoc\n> +++ b/Documentation/git-ls-remote.adoc\n> @@ -64,6 +65,13 @@ OPTIONS\n>  \tupload-pack only shows the symref HEAD, so it will be the only\n>  \tone shown by ls-remote.\n>  \n> +--show-object-format::\n> +\tShow the object format (hash algorithm, e.g. `sha1` or `sha256`) used\n> +\tby the remote repository before printing the references, on a line of\n> +\tits own. This also works for a remote repo without any refs, which is\n> +\tuseful to find out which object format to use for a local repository,\n\nA bit curious that you first say \"repo\" and then \"repository\". I'd just\ndrop \"repo\".\n\n> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c\n> index fe77829557..6d961f9961 100644\n> --- a/builtin/ls-remote.c\n> +++ b/builtin/ls-remote.c\n> @@ -150,6 +154,8 @@ int cmd_ls_remote(int argc,\n>  \n>  \tif (!dest && !quiet)\n>  \t\tfprintf(stderr, \"From %s\\n\", remote->url.v[0]);\n> +\tif (show_object_format)\n> +\t\tprintf(\"%s\\n\", transport_get_hash_algo(transport)->name);\n\nShould we maybe make this a tiny bit more extensible by not printing the\nobject format without any kind of prefix? We could for example instead\nprint \"object-format: %s\", which would allow us to add more fields in\nthe future without the need to make parsers be order-dependent.\n\nAlso, one more question I had is whether we know that the hash algo will\nalways be populated here. I would assume so, as we have this logic a\ncouple lines further up:\n\n\tref = transport_get_remote_refs(transport, &transport_options);\n\tif (ref) {\n\t\tint hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));\n\t\trepo_set_hash_algo(the_repository, hash_algo);\n\t}\n\nBut in theory, this logic would also work alright if the hash was NULL.\n\n> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh\n> index 2e1d4f7586..7e82154fe4 100755\n> --- a/t/t5512-ls-remote.sh\n> +++ b/t/t5512-ls-remote.sh\n> @@ -332,6 +332,52 @@ test_expect_success 'indicate no refs in v0 standards-compliant empty remote' '\n>  \ttest_expect_code 2 git ls-remote --exit-code --upload-pack=./cat-input .\n>  '\n>  \n> +# Run \"ls-remote --show-object-format\" with the given arguments over\n> +# protocol v0 and v2, and compare its output with \"expect\".\n> +test_show_object_format () {\n> +\tfor version in 0 2\n> +\tdo\n> +\t\tgit -c protocol.version=$version \\\n> +\t\t\tls-remote --show-object-format \"$@\" >actual &&\n> +\t\ttest_cmp expect actual || return 1\n\nIt's a bit weird that we expect the caller to already have written\n`expect`. A better interface would be to have them call the expected\nobject format as another parameter.\n\n> +\tdone\n> +}\n> +\n> +test_expect_success 'ls-remote --show-object-format with empty sha1 remote' '\n> +\tgit init --bare --object-format=sha1 empty-sha1.git &&\n> +\techo sha1 >expect &&\n> +\ttest_show_object_format empty-sha1.git\n> +'\n> +\n> +test_expect_success 'ls-remote --show-object-format with empty sha256 remote' '\n> +\tgit init --bare --object-format=sha256 empty-sha256.git &&\n> +\techo sha256 >expect &&\n> +\ttest_show_object_format empty-sha256.git\n> +'\n\nWe could easily deduplicate these tests by looping around `for hash in\nsha1 sha256`.\n\nThanks!\n\nPatrick\n\n"},{"id":"557580","messageId":"87cxsjxmky.fsf@collabora.com","threadId":"66782","inReplyTo":"auyO7lmLKD2OSwnD@pks.im","subject":"Re: [PATCH] ls-remote: add --show-object-format","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-05T16:35:57Z","receivedAt":"2026-11-05T16:35:57Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"Hi Patrick and thank you for the awesome review, as always.\n\nI'll let this sit for about 1 week to also give others a chance to\nreview, then send v2 addresing all your feedback.\n\nOn Thu, 05 Nov 2026, Patrick Steinhardt <ps@pks.im> wrote:\n<snip>\n>> diff --git a/Documentation/git-ls-remote.adoc b/Documentation/git-ls-remote.adoc\n>> index d71c4ab3e2..1abf7b60b7 100644\n>> --- a/Documentation/git-ls-remote.adoc\n>> +++ b/Documentation/git-ls-remote.adoc\n>> @@ -64,6 +65,13 @@ OPTIONS\n>>  \tupload-pack only shows the symref HEAD, so it will be the only\n>>  \tone shown by ls-remote.\n>>  \n>> +--show-object-format::\n>> +\tShow the object format (hash algorithm, e.g. `sha1` or `sha256`) used\n>> +\tby the remote repository before printing the references, on a line of\n>> +\tits own. This also works for a remote repo without any refs, which is\n>> +\tuseful to find out which object format to use for a local repository,\n>\n> A bit curious that you first say \"repo\" and then \"repository\". I'd just\n> drop \"repo\".\n\nInitially I wrote repository twice then the lines didn't fit, so I cut\nrepository -> repo to make them fit. :)\n\nEnglish is also not my first nor second languege, so I tend to keep\nrewriting multiple times before sending. It's still not \"good\" on the\nNth read, tbh.\n\nI'll try to improve this further to avoid redundancies, for e.g. I just\nrealized I wrote \"--show-objoct-format\" then immediately I repeated \"Show\nthe object format on the next line\". =)\n\n>\n>> diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c\n>> index fe77829557..6d961f9961 100644\n>> --- a/builtin/ls-remote.c\n>> +++ b/builtin/ls-remote.c\n>> @@ -150,6 +154,8 @@ int cmd_ls_remote(int argc,\n>>  \n>>  \tif (!dest && !quiet)\n>>  \t\tfprintf(stderr, \"From %s\\n\", remote->url.v[0]);\n>> +\tif (show_object_format)\n>> +\t\tprintf(\"%s\\n\", transport_get_hash_algo(transport)->name);\n>\n> Should we maybe make this a tiny bit more extensible by not printing the\n> object format without any kind of prefix? We could for example instead\n> print \"object-format: %s\", which would allow us to add more fields in\n> the future without the need to make parsers be order-dependent.\n\nYes, this is a great idea, will do in v2.\n\n(I just need to know the sha1 vs sha256 information, the format can be\nanything at all, no strong preference on my side).\n\n>\n> Also, one more question I had is whether we know that the hash algo will\n> always be populated here. I would assume so, as we have this logic a\n> couple lines further up:\n>\n> \tref = transport_get_remote_refs(transport, &transport_options);\n> \tif (ref) {\n> \t\tint hash_algo = hash_algo_by_ptr(transport_get_hash_algo(transport));\n> \t\trepo_set_hash_algo(the_repository, hash_algo);\n> \t}\n>\n> But in theory, this logic would also work alright if the hash was\n> NULL.\n\nYes, the hash format will always be populated by the time we call\ntransport_get_hash_algo() here.\n\n>> diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh\n>> index 2e1d4f7586..7e82154fe4 100755\n>> --- a/t/t5512-ls-remote.sh\n>> +++ b/t/t5512-ls-remote.sh\n>> @@ -332,6 +332,52 @@ test_expect_success 'indicate no refs in v0 standards-compliant empty remote' '\n>>  \ttest_expect_code 2 git ls-remote --exit-code --upload-pack=./cat-input .\n>>  '\n>>  \n>> +# Run \"ls-remote --show-object-format\" with the given arguments over\n>> +# protocol v0 and v2, and compare its output with \"expect\".\n>> +test_show_object_format () {\n>> +\tfor version in 0 2\n>> +\tdo\n>> +\t\tgit -c protocol.version=$version \\\n>> +\t\t\tls-remote --show-object-format \"$@\" >actual &&\n>> +\t\ttest_cmp expect actual || return 1\n>\n> It's a bit weird that we expect the caller to already have written\n> `expect`. A better interface would be to have them call the expected\n> object format as another parameter.\n\nAck, will do in v2.\n\n>> +\tdone\n>> +}\n>> +\n>> +test_expect_success 'ls-remote --show-object-format with empty sha1 remote' '\n>> +\tgit init --bare --object-format=sha1 empty-sha1.git &&\n>> +\techo sha1 >expect &&\n>> +\ttest_show_object_format empty-sha1.git\n>> +'\n>> +\n>> +test_expect_success 'ls-remote --show-object-format with empty sha256 remote' '\n>> +\tgit init --bare --object-format=sha256 empty-sha256.git &&\n>> +\techo sha256 >expect &&\n>> +\ttest_show_object_format empty-sha256.git\n>> +'\n>\n> We could easily deduplicate these tests by looping around `for hash in\n> sha1 sha256`.\n\nAck, will do in v2.\n\n"},{"id":"558281","messageId":"20261112085205.452463-1-adrian.ratiu@collabora.com","threadId":"66782","inReplyTo":"20261105104541.790881-1-adrian.ratiu@collabora.com","subject":"[PATCH v2] ls-remote: add --show-object-format","fromName":"Adrian Ratiu","fromEmail":"adrian.ratiu@collabora.com","sentAt":"2026-11-12T08:52:05Z","receivedAt":"2026-11-12T08:52:05Z","isPatch":true,"sender":{"key":"adrian.ratiu@collabora.com","avatar":"https://avatars.githubusercontent.com/u/12472556?v=4"},"body":"While working on JJ sha256 remote support (it uses Git for networking),\nI noticed there is no way to get the object format of a repo without\ncloning it. [1]\n\nGit clone learns the remote format during the protocol handshake, but\nit is not shown anywhere else. For example, when creating an empty repo\nand running \"git fetch\":\n\n1. If the remote has references, fetch can fail with a mismatch error\nand \"git ls-remote\" shows the format indirectly through the length\nof the object IDs. Not ideal, but then it can be figured out eventually,\nat least as long as no future hash algorithm has the same length as an\nexisting one.\n\n2. If the remote is empty, \"git ls-remote\" prints nothing and fetch\nsucceeds, so the new local repo can silently get the wrong format,\nwhich only shows up later, on the first push.\n\nTo fill this gap, add a ls-remote --show-object-format option which\nprints the object format learned from the remote on a line of its own,\nbefore the references, as \"object-format: <format>\". The prefix leaves\nroom for printing more remote properties in the future, without making\nparsers depend on the order of the lines.\n\n[1]: https://github.com/jj-vcs/jj/issues/3813\n\nSigned-off-by: Adrian Ratiu <adrian.ratiu@collabora.com>\n---\nChanges between v1 -> v2:\n* Print \"object-format: <format>\" instead of just \"<format>\". (Patrick)\n* Reworded the --show-object-format documentation. (Patrick)\n* Test helper now takes the expected format as an arg. (Patrick)\n* Combined the sha1/sha256 tests in a single loop. (Patrick)\n* Minor typo fix.\n---\n Documentation/git-ls-remote.adoc | 11 +++++++++-\n builtin/ls-remote.c              |  9 +++++++-\n t/t5512-ls-remote.sh             | 37 ++++++++++++++++++++++++++++++++\n 3 files changed, 55 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-ls-remote.adoc b/Documentation/git-ls-remote.adoc\nindex d71c4ab3e2..5d80967df7 100644\n--- a/Documentation/git-ls-remote.adoc\n+++ b/Documentation/git-ls-remote.adoc\n@@ -11,7 +11,8 @@ SYNOPSIS\n [verse]\n 'git ls-remote' [--branches] [--tags] [--refs] [--upload-pack=<exec>]\n \t      [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]\n-\t      [--symref] [<repository> [<patterns>...]]\n+\t      [--symref] [--show-object-format]\n+\t      [<repository> [<patterns>...]]\n \n DESCRIPTION\n -----------\n@@ -64,6 +65,14 @@ OPTIONS\n \tupload-pack only shows the symref HEAD, so it will be the only\n \tone shown by ls-remote.\n \n+--show-object-format::\n+\tBefore the references, print the object format (hash algorithm)\n+\tof the remote on a line of its own, in the form\n+\t`object-format: <format>`, e.g. `object-format: sha256`. This\n+\talso works for remotes without any refs, so it can be used to\n+\tfind out which object format a local repository needs before\n+\tfetching from or pushing to the remote.\n+\n --sort=<key>::\n \tSort based on the key given. Prefix `-` to sort in descending order\n \tof the value. Supports \"version:refname\" or \"v:refname\" (tag names\ndiff --git a/builtin/ls-remote.c b/builtin/ls-remote.c\nindex fe77829557..1d7bb578b3 100644\n--- a/builtin/ls-remote.c\n+++ b/builtin/ls-remote.c\n@@ -12,7 +12,8 @@\n static const char * const ls_remote_usage[] = {\n \tN_(\"git ls-remote [--branches] [--tags] [--refs] [--upload-pack=<exec>]\\n\"\n \t   \"              [-q | --quiet] [--exit-code] [--get-url] [--sort=<key>]\\n\"\n-\t   \"              [--symref] [<repository> [<patterns>...]]\"),\n+\t   \"              [--symref] [--show-object-format]\\n\"\n+\t   \"              [<repository> [<patterns>...]]\"),\n \tNULL\n };\n \n@@ -49,6 +50,7 @@ int cmd_ls_remote(int argc,\n \tint quiet = 0;\n \tint status = 0;\n \tint show_symref_target = 0;\n+\tint show_object_format = 0;\n \tconst char *uploadpack = NULL;\n \tstruct strvec pattern = STRVEC_INIT;\n \tstruct transport_ls_refs_options transport_options =\n@@ -89,6 +91,8 @@ int cmd_ls_remote(int argc,\n \t\t\t      2, PARSE_OPT_NOCOMPLETE),\n \t\tOPT_BOOL(0, \"symref\", &show_symref_target,\n \t\t\t N_(\"show underlying ref in addition to the object pointed by it\")),\n+\t\tOPT_BOOL(0, \"show-object-format\", &show_object_format,\n+\t\t\t N_(\"show the object format used by the remote repository\")),\n \t\tOPT_STRING_LIST('o', \"server-option\", &server_options, N_(\"server-specific\"), N_(\"option to transmit\")),\n \t\tOPT_END()\n \t};\n@@ -150,6 +154,9 @@ int cmd_ls_remote(int argc,\n \n \tif (!dest && !quiet)\n \t\tfprintf(stderr, \"From %s\\n\", remote->url.v[0]);\n+\tif (show_object_format)\n+\t\tprintf(\"object-format: %s\\n\",\n+\t\t       transport_get_hash_algo(transport)->name);\n \tfor ( ; ref; ref = ref->next) {\n \t\tstruct ref_array_item *item;\n \t\tif (!check_ref_type(ref, flags))\ndiff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh\nindex 2e1d4f7586..1b063a586a 100755\n--- a/t/t5512-ls-remote.sh\n+++ b/t/t5512-ls-remote.sh\n@@ -332,6 +332,43 @@ test_expect_success 'indicate no refs in v0 standards-compliant empty remote' '\n \ttest_expect_code 2 git ls-remote --exit-code --upload-pack=./cat-input .\n '\n \n+# Run \"ls-remote --show-object-format\" with the given arguments over\n+# protocol v0 and v2, and check that it prints the object format given\n+# as the first argument, followed by the same refs as plain \"ls-remote\".\n+test_show_object_format () {\n+\tformat=$1 &&\n+\tshift &&\n+\techo \"object-format: $format\" >expect &&\n+\tgit ls-remote \"$@\" >>expect &&\n+\tfor version in 0 2\n+\tdo\n+\t\tgit -c protocol.version=$version \\\n+\t\t\tls-remote --show-object-format \"$@\" >actual &&\n+\t\ttest_cmp expect actual || return 1\n+\tdone\n+}\n+\n+for hash in sha1 sha256\n+do\n+\ttest_expect_success \"ls-remote --show-object-format with empty $hash remote\" '\n+\t\tgit init --bare --object-format=$hash empty-$hash.git &&\n+\t\ttest_show_object_format $hash empty-$hash.git\n+\t'\n+\n+\ttest_expect_success \"ls-remote --show-object-format with $hash remote\" '\n+\t\tgit init --object-format=$hash repo-$hash &&\n+\t\ttest_commit -C repo-$hash one &&\n+\t\ttest_show_object_format $hash repo-$hash HEAD\n+\t'\n+done\n+\n+test_expect_success 'ls-remote --show-object-format outside repository' '\n+\tnongit git init --bare --object-format=sha256 empty-nongit.git &&\n+\techo \"object-format: sha256\" >expect &&\n+\tnongit git ls-remote --show-object-format empty-nongit.git >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_expect_success 'ls-remote works outside repository' '\n \t# It is important for this repo to be inside the nongit\n \t# area, as we want a repo name that does not include\n-- \n2.56.0\n\n\n"},{"id":"558326","messageId":"xmqqfqx5kjoq.fsf@gitster.g","threadId":"66782","inReplyTo":"20261112085205.452463-1-adrian.ratiu@collabora.com","subject":"Re: [PATCH v2] ls-remote: add --show-object-format","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-12T18:07:17Z","receivedAt":"2026-11-12T18:07:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Adrian Ratiu <adrian.ratiu@collabora.com> writes:\n\n> @@ -150,6 +154,9 @@ int cmd_ls_remote(int argc,\n>  \n>  \tif (!dest && !quiet)\n>  \t\tfprintf(stderr, \"From %s\\n\", remote->url.v[0]);\n> +\tif (show_object_format)\n> +\t\tprintf(\"object-format: %s\\n\",\n> +\t\t       transport_get_hash_algo(transport)->name);\n\nOK.  transport_get_hash_algo() just grabs transport->hash_algo which\nwas relayed from connect.c:get_remote_refs(), so even when talking\nover an old protocol that does not explicitly declare, we get\nGIT_HASH_SHA1_LEGACY.  IOW, no need to worry about hitting an \"eh,\nwe do not know that\" here.\n\nLooking good.\n\n> +# Run \"ls-remote --show-object-format\" with the given arguments over\n> +# protocol v0 and v2, and check that it prints the object format given\n> +# as the first argument, followed by the same refs as plain \"ls-remote\".\n> +test_show_object_format () {\n> +\tformat=$1 &&\n> +\tshift &&\n> +\techo \"object-format: $format\" >expect &&\n> +\tgit ls-remote \"$@\" >>expect &&\n> +\tfor version in 0 2\n> +\tdo\n> +\t\tgit -c protocol.version=$version \\\n> +\t\t\tls-remote --show-object-format \"$@\" >actual &&\n> +\t\ttest_cmp expect actual || return 1\n> +\tdone\n> +}\n> +\n> +for hash in sha1 sha256\n> +do\n> +\ttest_expect_success \"ls-remote --show-object-format with empty $hash remote\" '\n> +\t\tgit init --bare --object-format=$hash empty-$hash.git &&\n> +\t\ttest_show_object_format $hash empty-$hash.git\n> +\t'\n> +\n> +\ttest_expect_success \"ls-remote --show-object-format with $hash remote\" '\n> +\t\tgit init --object-format=$hash repo-$hash &&\n> +\t\ttest_commit -C repo-$hash one &&\n> +\t\ttest_show_object_format $hash repo-$hash HEAD\n> +\t'\n> +done\n> +\n> +test_expect_success 'ls-remote --show-object-format outside repository' '\n> +\tnongit git init --bare --object-format=sha256 empty-nongit.git &&\n> +\techo \"object-format: sha256\" >expect &&\n> +\tnongit git ls-remote --show-object-format empty-nongit.git >actual &&\n> +\ttest_cmp expect actual\n> +'\n\nAnd we seem to have adequate test coverage.\n\nThanks.\n\n"},{"id":"558373","messageId":"ava7178U9hXzPy1Y@pks.im","threadId":"66782","inReplyTo":"20261112085205.452463-1-adrian.ratiu@collabora.com","subject":"Re: [PATCH v2] ls-remote: add --show-object-format","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-13T07:27:19Z","receivedAt":"2026-11-13T07:27:19Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Thu, Nov 12, 2026 at 10:52:05AM +0200, Adrian Ratiu wrote:\n> Changes between v1 -> v2:\n> * Print \"object-format: <format>\" instead of just \"<format>\". (Patrick)\n> * Reworded the --show-object-format documentation. (Patrick)\n> * Test helper now takes the expected format as an arg. (Patrick)\n> * Combined the sha1/sha256 tests in a single loop. (Patrick)\n> * Minor typo fix.\n\nThanks, I'm happy with this version.\n\nPatrick\n\n"}]}