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

[PATCH 08/10] submodule: support "--" with no other arguments

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Oct 17, 2022, 12:09 UTC
Message-ID
<patch-08.10-8dbb81e2fa5-20221017T115544Z-avarab@gmail.com>
In-Reply-To
<cover-00.10-00000000000-20221017T115544Z-avarab@gmail.com>

Address an edge case that "git-submodule.sh" has had all along, but which became painfully obvious in the *.sh to *.c migration in the preceding commit.

We didn't support the "--" delimiter in the argument-less invocation. Let's not bend over backwards to behave unusually in this scenario, simply accepting "--" is harmless.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/git-submodule.txt |  2 +-
 builtin/submodule.c             | 12 ++----------
 t/t7400-submodule-basic.sh      |  4 ++--
 3 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 4d3ab6b9f92..345ebcafb9c 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -9,7 +9,7 @@ git-submodule - Initialize, update or inspect submodules
 SYNOPSIS
 --------
 [verse]
-'git submodule' [--quiet] [--cached]
+'git submodule' [--quiet] [--cached] [--]
 'git submodule' [--quiet] add [<options>] [--] <repository> [<path>]
 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
 'git submodule' [--quiet] init [--] [<path>...]
diff --git a/builtin/submodule.c b/builtin/submodule.c
index 7e3499f3376..1d77f2d0964 100644
--- a/builtin/submodule.c
+++ b/builtin/submodule.c
@@ -8,7 +8,7 @@
 #include "strvec.h"
 
 #define BUILTIN_SUBMODULE_USAGE \
-	"git submodule [--quiet] [--cached]"
+	"git submodule [--quiet] [--cached] [--]"
 
 #define BUILTIN_SUBMODULE_ADD_USAGE \
 	N_("git submodule [--quiet] add [-b <branch>] [-f | --force] [--name <name>]\n" \
@@ -91,14 +91,6 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix,
 	argv++;
 	argc--;
 
-	/*
-	  * This is stupid, but don't support "[--]" to
-	 * subcommand-less "git-submodule" for now.
-	 */
-	if (!strcmp(cmd, "--") || !strcmp(cmd, "--end-of-options"))
-		usage_msg_optf(_("need explicit sub-command name to delimit with '%s'"),
-			       git_submodule_usage, options, cmd);
-
 	/* Options that need to go before user-supplied options */
 	if (!strcmp(cmd, "absorbgitdirs"))
 		do_quiet_cache = 0;
@@ -133,7 +125,7 @@ int cmd_submodule(int argc, const char **argv, const char *prefix)
 	};
 
 	argc = parse_options(argc, argv, prefix, options, git_submodule_usage,
-			     PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_KEEP_DASHDASH);
+			     PARSE_OPT_STOP_AT_NON_OPTION);
 
 	/*
 	 * Tell the rest of git that any URLs we get don't come
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index 19df3407ef1..c524398e805 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -25,8 +25,8 @@ test_expect_success 'submodule usage: --recursive' '
 '
 
 test_expect_success 'submodule usage: status --' '
-	test_expect_code 129 git submodule -- &&
-	test_expect_code 129 git submodule --end-of-options
+	git submodule -- &&
+	git submodule --end-of-options
 '
 
 for opt in '--quiet'
-- 
2.38.0.1091.gf9d18265e59
Previous: Glen ChooNext: Ævar Arnfjörð Bjarmason
Message 12 of 18 in “submodule: make it a built-in, remove git-submodule.sh”
  1. 00/10 submodule: make it a built-in, remove git-submodule.shÆvar Arnfjörð Bjarmason, Oct 17, 2022
  2. 01/10 git-submodule.sh: create a "case" dispatch statementÆvar Arnfjörð Bjarmason, Oct 17, 2022
  3. 02/10 git-submodule.sh: dispatch "sync" to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  4. Glen ChooOct 20, 2022
  5. 04/10 git-submodule.sh: dispatch "foreach" to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  6. Glen ChooOct 20, 2022
  7. 03/10 git-submodule.sh: dispatch directly to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  8. 06/10 git-submodule.sh: don't support top-level "--cached"Ævar Arnfjörð Bjarmason, Oct 17, 2022
  9. Glen ChooOct 20, 2022
  10. 05/10 git-submodule.sh: dispatch "update" to helperÆvar Arnfjörð Bjarmason, Oct 17, 2022
  11. Glen ChooOct 20, 2022
  12. 08/10 submodule: support "--" with no other argumentsÆvar Arnfjörð Bjarmason, Oct 17, 2022
  13. 09/10 submodule: support sub-command-less "--recursive" optionÆvar Arnfjörð Bjarmason, Oct 17, 2022
  14. Glen ChooOct 20, 2022
  15. 07/10 submodule: make it a built-in, remove git-submodule.shÆvar Arnfjörð Bjarmason, Oct 17, 2022
  16. Glen ChooOct 20, 2022
  17. 10/10 submodule: don't use a subprocess to invoke "submodule--helper"Ævar Arnfjörð Bjarmason, Oct 17, 2022
  18. Glen ChooOct 20, 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.