git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Glen Choo" <chooglen@google.com>,
	"Jonas Bernoulli" <jonas@bernoul.li>, "Jeff King" <peff@peff.net>,
	"Emily Shaffer" <emilyshaffer@google.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [PATCH 09/10] submodule: support sub-command-less "--recursive" option
Date: Mon, 17 Oct 2022 14:09:24 +0200	[thread overview]
Message-ID: <patch-09.10-7f232c5e503-20221017T115544Z-avarab@gmail.com> (raw)
In-Reply-To: <cover-00.10-00000000000-20221017T115544Z-avarab@gmail.com>

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");
+
 	if (!strcmp(cmd, "absorbgitdirs"))
 		do_quiet_cache = 0;
 	else if (!strcmp(cmd, "update"))
@@ -116,11 +123,14 @@ int cmd_submodule(int argc, const char **argv, const char *prefix)
 {
 	int opt_quiet = 0;
 	int opt_cached = 0;
+	int opt_recursive = 0;
 	struct child_process cp = CHILD_PROCESS_INIT;
 	struct option options[] = {
 		OPT__QUIET(&opt_quiet, N_("be quiet")),
 		OPT_BOOL(0, "cached", &opt_cached,
 			 N_("print the OID of submodules")),
+		OPT_BOOL(0, "recursive", &opt_recursive,
+			 N_("recurse into nested submodules")),
 		OPT_END()
 	};
 
@@ -133,7 +143,7 @@ int cmd_submodule(int argc, const char **argv, const char *prefix)
 	 */
 	strvec_push(&cp.env, "GIT_PROTOCOL_FROM_USER=0");
 	setup_helper_args(argc, argv, prefix, opt_quiet, opt_cached,
-			  &cp.args, options);
+			  opt_recursive, &cp.args, options);
 
 	cp.git_cmd = 1;
 	cp.no_stdin = 0; /* for git submodule foreach */
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 &&
-- 
2.38.0.1091.gf9d18265e59


  parent reply	other threads:[~2022-10-17 12:10 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-17 12:09 [PATCH 00/10] submodule: make it a built-in, remove git-submodule.sh Ævar Arnfjörð Bjarmason
2022-10-17 12:09 ` [PATCH 01/10] git-submodule.sh: create a "case" dispatch statement Ævar Arnfjörð Bjarmason
2022-10-17 12:09 ` [PATCH 02/10] git-submodule.sh: dispatch "sync" to helper Ævar Arnfjörð Bjarmason
2022-10-20 20:42   ` Glen Choo
2022-10-17 12:09 ` [PATCH 03/10] git-submodule.sh: dispatch directly " Ævar Arnfjörð Bjarmason
2022-10-17 12:09 ` [PATCH 04/10] git-submodule.sh: dispatch "foreach" " Ævar Arnfjörð Bjarmason
2022-10-20 21:14   ` Glen Choo
2022-10-17 12:09 ` [PATCH 05/10] git-submodule.sh: dispatch "update" " Ævar Arnfjörð Bjarmason
2022-10-20 21:50   ` Glen Choo
2022-10-17 12:09 ` [PATCH 06/10] git-submodule.sh: don't support top-level "--cached" Ævar Arnfjörð Bjarmason
2022-10-20 22:14   ` Glen Choo
2022-10-17 12:09 ` [PATCH 07/10] submodule: make it a built-in, remove git-submodule.sh Ævar Arnfjörð Bjarmason
2022-10-20 22:49   ` Glen Choo
2022-10-17 12:09 ` [PATCH 08/10] submodule: support "--" with no other arguments Ævar Arnfjörð Bjarmason
2022-10-17 12:09 ` Ævar Arnfjörð Bjarmason [this message]
2022-10-20 23:05   ` [PATCH 09/10] submodule: support sub-command-less "--recursive" option Glen Choo
2022-10-17 12:09 ` [PATCH 10/10] submodule: don't use a subprocess to invoke "submodule--helper" Ævar Arnfjörð Bjarmason
2022-10-20 23:18   ` Glen Choo

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

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

  git send-email \
    --in-reply-to=patch-09.10-7f232c5e503-20221017T115544Z-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=chooglen@google.com \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jonas@bernoul.li \
    --cc=peff@peff.net \
    /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.
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 NNTP newsgroup(s).