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

[PATCH 4/5] submodule: introduce reversive shorthand mode

From
WHWilliam Hatfield <whatfield.git@gmail.com>
Date
Jan 31, 2026, 21:43 UTC
Message-ID
<20260131214309.1899376-5-whatfield.git@gmail.com>
In-Reply-To
<20260131214309.1899376-1-whatfield.git@gmail.com>
Add --reversive as a convenience shorthand that combines:
 - --recursive: process all nested submodules
 - --reverse-traversal: visit children before parents (post-order)
 - --append-superproject: run command in superproject after all submodules

This enables a single flag to achieve full post-order traversal from the deepest submodules up to the superproject, which is useful for build systems, cleanup scripts, or any operation that needs to process dependencies before dependents.

Signed-off-by: William Hatfield <whatfield.git@gmail.com>
---
 builtin/submodule--helper.c    | 11 ++++++++++-
 git-submodule.sh               |  5 +++++
 t/t7425-submodule-reversion.sh |  6 +++---
 3 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index f6cba87a05..26365b397b 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -432,6 +432,7 @@ static int module_foreach(int argc, const char **argv, const char *prefix,
 	struct foreach_cb info = FOREACH_CB_INIT;
 	struct pathspec pathspec = { 0 };
 	struct module_list list = MODULE_LIST_INIT;
+	int reversive = 0;
 	struct option module_foreach_options[] = {
 		OPT__SUPER_PREFIX(&info.super_prefix),
 		OPT__QUIET(&info.quiet, N_("suppress output of entering each submodule command")),
@@ -441,10 +442,12 @@ static int module_foreach(int argc, const char **argv, const char *prefix,
 			 N_("traverse submodules in reverse order (post-order)")),
 		OPT_BOOL(0, "append-superproject", &info.append_superproject,
 			 N_("also run command in superproject after submodules")),
+		OPT_BOOL(0, "reversive", &reversive,
+			 N_("shorthand for --recursive --reverse-traversal --append-superproject")),
 		OPT_END()
 	};
 	const char *const git_submodule_helper_usage[] = {
-		N_("git submodule foreach [--quiet] [--recursive] [--reverse-traversal] [--append-superproject] [--] <command>"),
+		N_("git submodule foreach [--quiet] [--recursive] [--reverse-traversal] [--append-superproject] [--reversive] [--] <command>"),
 		NULL
 	};
 	int ret = 1;
@@ -452,6 +455,12 @@ static int module_foreach(int argc, const char **argv, const char *prefix,
 	argc = parse_options(argc, argv, prefix, module_foreach_options,
 			     git_submodule_helper_usage, 0);
 
+	if (reversive) {
+		info.recursive = 1;
+		info.reverse_traversal = 1;
+		info.append_superproject = 1;
+	}
+
 	if (module_list_compute(NULL, prefix, &pathspec, &list) < 0)
 		goto cleanup;
 
diff --git a/git-submodule.sh b/git-submodule.sh
index 58682a287d..e1b81344f6 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -179,6 +179,11 @@ cmd_foreach()
 		--append-superproject)
 			append_superproject=$1
 			;;
+		--reversive)
+			recursive=--recursive
+			reverse_traversal=--reverse-traversal
+			append_superproject=--append-superproject
+			;;
 		-*)
 			usage
 			;;
diff --git a/t/t7425-submodule-reversion.sh b/t/t7425-submodule-reversion.sh
index 7a6a54de15..88f61b0f06 100755
--- a/t/t7425-submodule-reversion.sh
+++ b/t/t7425-submodule-reversion.sh
@@ -231,14 +231,14 @@ EOF
 	test_cmp expect actual
 '
 
-test_expect_failure '--reversive parses' '
+test_expect_success '--reversive parses' '
 	(
 		cd reversive/top &&
 		git submodule foreach --reversive "true"
 	)
 '
 
-test_expect_failure '--reversive runs' '
+test_expect_success '--reversive runs' '
 	(
 		cd reversive/top &&
 		git submodule --quiet foreach --reversive "echo \$displaypath"
@@ -261,7 +261,7 @@ EOF
 	test_cmp expect actual
 '
 
-test_expect_failure '--reversive stops on command failure' '
+test_expect_success '--reversive stops on command failure' '
 	(
 		cd reversive/top &&
 		git submodule foreach --reversive "true" &&
-- 
2.53.0-rc0
Previous: William HatfieldNext: William Hatfield
Message 5 of 11 in “submodule: add 'reversive' traversal options to foreach”
  1. 0/5 submodule: add 'reversive' traversal options to foreachWilliam Hatfield, Jan 31, 2026
  2. 1/5 t7425: add tests for reversive submodule traversalWilliam Hatfield, Jan 31, 2026
  3. 2/5 submodule: teach and plumb reverse-traversal behaviorWilliam Hatfield, Jan 31, 2026
  4. 3/5 submodule: teach and plumb append-superproject behaviorWilliam Hatfield, Jan 31, 2026
  5. 4/5 submodule: introduce reversive shorthand modeWilliam Hatfield, Jan 31, 2026
  6. 5/5 doc: document reversive traversal and related modesWilliam Hatfield, Jan 31, 2026
  7. Jean-Noël AVILAFeb 1, 2026
  8. William HatfieldFeb 2, 2026
  9. Junio C HamanoFeb 2, 2026
  10. William HatfieldFeb 2, 2026
  11. Junio C HamanoFeb 2, 2026

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.