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

Re: [PATCH 09/10] submodule: support sub-command-less "--recursive" option

From
Glen Choo <chooglen@google.com>
Date
Oct 20, 2022, 23:05 UTC
Message-ID
<kl6lmt9qxfj5.fsf@chooglen-macbookpro.roam.corp.google.com>
In-Reply-To
<patch-09.10-7f232c5e503-20221017T115544Z-avarab@gmail.com>
Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes:
Show 61 quoted lines
> The inability to specify "--recursive" when we're not providing a
> sub-command name appears to have been an omission in 15fc56a8536 (git
> submodule foreach: Add --recursive to recurse into nested submodules,
> 2009-08-19). Let's support it along with the other "status" options.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  Documentation/git-submodule.txt |  2 +-
>  builtin/submodule.c             | 16 +++++++++++++---
>  t/t7400-submodule-basic.sh      |  6 +-----
>  3 files changed, 15 insertions(+), 9 deletions(-)
>
> diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
> index 345ebcafb9c..0c918390f2f 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] [--recursive] [--]
>  '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 1d77f2d0964..ca8e273b6e9 100644
> --- a/builtin/submodule.c
> +++ b/builtin/submodule.c
> @@ -64,7 +64,8 @@ static const char * const git_submodule_usage[] = {
>  };
>  
>  static void setup_helper_args(int argc, const char **argv, const char *prefix,
> -			      int quiet, int cached, struct strvec *args,
> +			      int quiet, int cached, int recursive,
> +			      struct strvec *args,
>  			      const struct option *options)
>  {
>  	const char *cmd;
> @@ -79,10 +80,13 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix,
>  		return;
>  	}
>  
> -	/* Did we get --cached with a command? */
> +	/* Did we get a forbidden top-level option with a command? */
>  	if (cached)
>  		usage_msg_optf(_("'%s' option is only supported with explicit 'status'"),
>  			       git_submodule_usage, options, "--cached");
> +	if (recursive)
> +		usage_msg_optf(_("'%s' option is only supported with explicit 'status'"),
> +			       git_submodule_usage, options, "--recursive");
>  
>  
>  	/* Either a valid command, or submodule--helper will barf! */
> @@ -92,6 +96,9 @@ static void setup_helper_args(int argc, const char **argv, const char *prefix,
>  	argc--;
>  
>  	/* Options that need to go before user-supplied options */
> +	if (!strcmp(cmd, "status") && recursive)
> +		strvec_push(args, "--recursive");
> +

Unless I'm missing something, doesn't this do nothing because we don't set cmd = "status" when there is no subcommand, and instead, we return early?

Show 24 quoted lines
> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index c524398e805..7cafc2e1102 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -20,10 +20,6 @@ test_expect_success 'submodule usage: -h' '
>  	test_must_be_empty err
>  '
>  
> -test_expect_success 'submodule usage: --recursive' '
> -	test_expect_code 129 git submodule --recursive
> -'
> -
>  test_expect_success 'submodule usage: status --' '
>  	git submodule -- &&
>  	git submodule --end-of-options
> @@ -38,7 +34,7 @@ do
>  	'
>  done
>  
> -for opt in '--cached'
> +for opt in '--cached' '--recursive'
>  do
>  	test_expect_success "submodule usage: status $opt" '
>  		git submodule $opt &&

Frustratingly, it's not easy for me to test my hypothesis above because there don't seem to be any tests for the output of "git submodule status --recursive" :(

> -- 
> 2.38.0.1091.gf9d18265e59
Previous: Ævar Arnfjörð BjarmasonNext: Ævar Arnfjörð Bjarmason
Message 14 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.