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

[RFC PATCH v1 0/1] ls-remote: inconsistency from the order of args and opts

From
Teng Long <dyroneteng@gmail.com>
Date
Jan 14, 2022, 04:24 UTC
Message-ID
<cover.1642129840.git.dyroneteng@gmail.com>

It has a different results by executing "git ls-remote -heads origin" and "git ls-remote origin --heads". A test for reproduction is as follows:

@@ -0,0 +1,17 @@
+#!/bin/sh
+                                                                                                           
+test_description='test ls-tree for reproduction'
+
+. ./test-lib.sh
+
+
+test_must_fail 'Exchange the order of "--heads" and <remote>' '
+    git --version &&
+    git init "test.git" &&
+    test_commit -C "test.git" one &&
+    git -C "test.git" ls-remote --heads ./. > result.1 &&
+    git -C "test.git" ls-remote ./. --heads > result.2 &&
+    test_cmp result.1 result.2
+'
+
+test_done
--
2.34.1.391.g9ef3d6f133

"git -C "test.git" ls-remote ./. --heads" returns nothing here because
"ls-remote" supports to treat args as patterns to filter the refs list
, and "--heads" here as the pattern does not match any.

If a repo exists a ref which is named as "refs/heads/--heads", execute
`mgit ls-remote origin --heads` will return ("mgit" is a alias means
the git binary that is built by "master" in my env):
                                                                                                            
       0319b78d7c31e5203d79157fe82960db88cc4a54        refs/heads/--heads

If we execute again in terms of this patch by `git ls-remote origin --heads`:

      0319b78d7c31e5203d79157fe82960db88cc4a54        refs/heads/--heads
      0319b78d7c31e5203d79157fe82960db88cc4a54        refs/heads/master

And if we hope to let "--heads" to be treated as a "pattern", we can execute
`git ls-remote origin --heads -- "--heads"`:

      0319b78d7c31e5203d79157fe82960db88cc4a54        refs/heads/--heads

Personally, I think the second option is probably a little better, but there
are also possible backward compatibility issues, such as users ending branch
names with "-heads" and so on.

So I sent this patch to try to figure out if this was a requirement of the
original design, or if it was something that could really be improved, or if
we can find a better way to deal this issue with compatibility.

Thanks.

Teng Long (1):
  ls-remote: Make the output independent of the order of opts and
    <remote>

 builtin/ls-remote.c  |  3 +--
 t/t5512-ls-remote.sh | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

Range-diff against v0:
-:  ---------- > 1:  9ef3d6f133 ls-remote: Make the output independent of the order of opts and <remote>
-- 
2.34.1.391.g9ef3d6f133
Next: Teng Long
Message 1 of 18 in “ls-remote: inconsistency from the order of args and opts”
  1. 0/1 ls-remote: inconsistency from the order of args and optsTeng Long, Jan 14, 2022
  2. 1/1 ls-remote: Make the output independent of the order of opts and <remote>Teng Long, Jan 14, 2022
  3. Junio C HamanoJan 14, 2022
  4. Junio C HamanoJan 14, 2022
  5. Teng LongJan 14, 2022
  6. Junio C HamanoJan 15, 2022
  7. Ævar Arnfjörð BjarmasonJan 14, 2022
  8. Junio C HamanoJan 14, 2022
  9. Ævar Arnfjörð BjarmasonJan 14, 2022
  10. Junio C HamanoJan 14, 2022
  11. Ævar Arnfjörð BjarmasonJan 15, 2022
  12. Junio C HamanoJan 15, 2022
  13. brian m. carlsonJan 14, 2022
  14. Ævar Arnfjörð BjarmasonJan 15, 2022
  15. Junio C HamanoJan 15, 2022
  16. Ævar Arnfjörð BjarmasonJan 15, 2022
  17. Junio C HamanoJan 15, 2022
  18. Teng LongJan 17, 2022

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.