git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Teng Long <dyroneteng@gmail.com>
To: git@vger.kernel.org
Cc: tenglong.tl@alibaba-inc.com, Teng Long <dyroneteng@gmail.com>
Subject: [RFC PATCH v1 1/1] ls-remote: Make the output independent of the order of opts and <remote>
Date: Fri, 14 Jan 2022 12:24:23 +0800	[thread overview]
Message-ID: <9ef3d6f1338b06177ed22ed9453e2dcc9f1c3b7f.1642129840.git.dyroneteng@gmail.com> (raw)
In-Reply-To: <cover.1642129840.git.dyroneteng@gmail.com>

This commit is used to solve the problem of inconsistent execution
results caused by switching the order of parameters and options
in some scenarios. For example, if we execute the following commands:

   $/opt/git/master/bin/git ls-remote .git
   >3ea29ad061137e321853d64fb38b6c6e907546a0        HEAD
   >3ea29ad061137e321853d64fb38b6c6e907546a0        refs/heads/master
   >3 ea29ad061137e321853d64fb38b6c6e907546a0 refs/tags/v1.0

   $/opt/git/master/bin/git ls-remote --heads .git
   >3ea29ad061137e321853d64fb38b6c6e907546a0        refs/heads/master

   $/opt/git/master/bin/git ls-remote .git --heads
   >

   Please omit the ">" because they are just to make the output more
   intuitive. The tests are based on 2ae0a9cb82 (The fifth batch, 2021-12-22).
   in master.

Similarily "--tags", "--refs" and "--symref" also produces the same result
(no output print in this case).

The issue is caused by `ls-remote` command supports args as "patterns", which
will filter the refs list from <remote> through the trailing matching rule. In
these usages, Options can be differentiated and processed more accurately with
"patterns", otherwise the result might lead to confusion if user has a loss of
the context.

This commit sets "parse_opt_flags" value in "parse_options()" to 0, this will
let the commands produce the same result in this scenario. At the same time,
this commit does not break the current test cases in t5512.

Signed-off-by: Teng Long <dyroneteng@gmail.com>
---
 builtin/ls-remote.c  |  3 +--
 t/t5512-ls-remote.sh | 24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 2 deletions(-)

diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c
index 44448fa61d..45eeecdb71 100644
--- a/builtin/ls-remote.c
+++ b/builtin/ls-remote.c
@@ -80,8 +80,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
 
 	memset(&ref_array, 0, sizeof(ref_array));
 
-	argc = parse_options(argc, argv, prefix, options, ls_remote_usage,
-			     PARSE_OPT_STOP_AT_NON_OPTION);
+	argc = parse_options(argc, argv, prefix, options, ls_remote_usage, 0);
 	dest = argv[0];
 
 	packet_trace_identity("ls-remote");
diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh
index f53f58895a..7c51cc23d1 100755
--- a/t/t5512-ls-remote.sh
+++ b/t/t5512-ls-remote.sh
@@ -349,4 +349,28 @@ test_expect_success 'ls-remote prefixes work with all protocol versions' '
 	test_cmp expect actual.v2
 '
 
+test_expect_success 'ls-remote same result if exchange the order of --heads and <remote>' '
+	git ls-remote --heads self > expect.heads &&
+	git ls-remote self --heads > actual.heads &&
+	test_cmp expect.heads actual.heads
+'
+
+test_expect_success 'ls-remote same result if exchange the order of --tags and <remote>' '
+	git ls-remote --tags self > expect.tags &&
+	git ls-remote self --tags > actual.tags &&
+	test_cmp expect.tags actual.tags
+'
+
+test_expect_success 'ls-remote same result if exchange the order of --refs and <remote>' '
+	git ls-remote --refs self > expect.refs &&
+	git ls-remote self --refs > actual.refs &&
+	test_cmp expect.refs actual.refs
+'
+
+test_expect_success 'ls-remote same result if exchange the order of --symref and <remote>' '
+	git ls-remote --symref self > expect.symref &&
+	git ls-remote self --symref > actual.symref &&
+	test_cmp expect.symref actual.symref
+'
+
 test_done
-- 
2.34.1.391.g9ef3d6f133


  reply	other threads:[~2022-01-14  4:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14  4:24 [RFC PATCH v1 0/1] ls-remote: inconsistency from the order of args and opts Teng Long
2022-01-14  4:24 ` Teng Long [this message]
2022-01-14  5:47 ` Junio C Hamano
2022-01-14  6:27   ` Junio C Hamano
2022-01-14  6:42   ` Teng Long
2022-01-15  0:25     ` Junio C Hamano
2022-01-14 19:57   ` Ævar Arnfjörð Bjarmason
2022-01-14 20:42     ` Junio C Hamano
2022-01-14 20:57       ` Ævar Arnfjörð Bjarmason
2022-01-14 21:52         ` Junio C Hamano
2022-01-15  0:34           ` Ævar Arnfjörð Bjarmason
2022-01-15  1:01             ` Junio C Hamano
2022-01-14 21:12     ` brian m. carlson
2022-01-15  0:13       ` Ævar Arnfjörð Bjarmason
2022-01-15  0:50         ` Junio C Hamano
2022-01-15  1:02           ` Ævar Arnfjörð Bjarmason
2022-01-15  1:19             ` Junio C Hamano
2022-01-17  6:27 ` Teng Long

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9ef3d6f1338b06177ed22ed9453e2dcc9f1c3b7f.1642129840.git.dyroneteng@gmail.com \
    --to=dyroneteng@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=tenglong.tl@alibaba-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).