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

[PATCH 02/10] submodule update: add `--init-active` switch

From
BWBrandon Williams <bmwill@google.com>
Date
Feb 23, 2017, 23:47 UTC
Message-ID
<20170223234728.164111-3-bmwill@google.com>
In-Reply-To
<20170223234728.164111-1-bmwill@google.com>

The new switch `--init-active` initializes the submodules which are configured in `submodule.active` instead of those given as command line arguments before updating. In the first implementation this is made incompatible with further command line arguments as it is unclear what the user means by

    git submodule update --init --init-active <paths>

This new switch allows users to record more complex patterns as it saves retyping them whenever you invoke update.

Based on a patch by Stefan Beller <sbeller@google.com>
Signed-off-by: Brandon Williams <bmwill@google.com>
---
 Documentation/git-submodule.txt | 11 ++++++++++-
 git-submodule.sh                | 21 ++++++++++++++++++---
 t/t7400-submodule-basic.sh      | 39 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 918bd1d1b..626b9760a 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -14,7 +14,7 @@ SYNOPSIS
 'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
 'git submodule' [--quiet] init [--] [<path>...]
 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] <path>...)
-'git submodule' [--quiet] update [--init] [--remote] [-N|--no-fetch]
+'git submodule' [--quiet] update [--init[-active]] [--remote] [-N|--no-fetch]
 	      [--[no-]recommend-shallow] [-f|--force] [--rebase|--merge]
 	      [--reference <repository>] [--depth <depth>] [--recursive]
 	      [--jobs <n>] [--] [<path>...]
@@ -195,6 +195,10 @@ If the submodule is not yet initialized, and you just want to use the
 setting as stored in .gitmodules, you can automatically initialize the
 submodule with the `--init` option.
 
+You can configure a set of submodules using pathspec syntax in
+submodule.active you can use `--init-active` to initialize
+those before updating.
+
 If `--recursive` is specified, this command will recurse into the
 registered submodules, and update any nested submodules within.
 --
@@ -378,6 +382,11 @@ the submodule itself.
 	Initialize all submodules for which "git submodule init" has not been
 	called so far before updating.
 
+--init-active::
+	This option is only valid for the update command.
+	Initialize all submodules configured in "`submodule.active`"
+	that have not been updated before.
+
 --name::
 	This option is only valid for the add command. It sets the submodule's
 	name to the given string instead of defaulting to its path. The name
diff --git a/git-submodule.sh b/git-submodule.sh
index 554bd1c49..e5b9a8920 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -9,7 +9,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
    or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
-   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
+   or: $dashless [--quiet] update [--init[-active]] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
    or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
@@ -499,7 +499,12 @@ cmd_update()
 			progress="--progress"
 			;;
 		-i|--init)
-			init=1
+			test -z $init || test $init = by_args || die "$(gettext "Only one of --init or --init-active may be used.")"
+			init=by_args
+			;;
+		--init-active)
+			test -z $init || test $init = by_config || die "$(gettext "Only one of --init or --init-active may be used.")"
+			init=by_config
 			;;
 		--remote)
 			remote=1
@@ -568,7 +573,17 @@ cmd_update()
 
 	if test -n "$init"
 	then
-		cmd_init "--" "$@" || return
+		if test "$init" = "by_config"
+		then
+			if test $# -gt 0
+			then
+				die "$(gettext "path arguments are incompatible with --init-active")"
+			fi
+			cmd_init "--" $(git config --get-all submodule.active) || return
+		else
+			cmd_init "--" "$@" || return
+		fi
+
 	fi
 
 	{
diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index b77cce8e4..f5df0a5b4 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -1116,5 +1116,44 @@ test_expect_success 'submodule helper list is not confused by common prefixes' '
 	test_cmp expect actual
 '
 
+test_expect_success 'setup superproject with submodules' '
+	git init sub1 &&
+	test_commit -C sub1 test &&
+	test_commit -C sub1 test2 &&
+	git init multisuper &&
+	git -C multisuper submodule add ../sub1 sub0 &&
+	git -C multisuper submodule add ../sub1 sub1 &&
+	git -C multisuper submodule add ../sub1 sub2 &&
+	git -C multisuper submodule add ../sub1 sub3 &&
+	git -C multisuper commit -m "add some submodules"
+'
+
+cat >expect <<-EOF
+-sub0
+ sub1 (test2)
+ sub2 (test2)
+ sub3 (test2)
+EOF
+
+test_expect_success 'submodule update --init with a specification' '
+	test_when_finished "rm -rf multisuper_clone" &&
+	pwd=$(pwd) &&
+	git clone file://"$pwd"/multisuper multisuper_clone &&
+	git -C multisuper_clone submodule update --init . ":(exclude)sub0" &&
+	git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'submodule update --init-active' '
+	test_when_finished "rm -rf multisuper_clone" &&
+	pwd=$(pwd) &&
+	git clone file://"$pwd"/multisuper multisuper_clone &&
+	git -C multisuper_clone config submodule.active "." &&
+	git -C multisuper_clone config --add submodule.active ":(exclude)sub0" &&
+	git -C multisuper_clone submodule update --init-active &&
+	git -C multisuper_clone submodule status |cut -c 1,43- >actual &&
+	test_must_fail git -C multisuper_clone submodule update --init-active sub0 &&
+	test_cmp expect actual
+'
 
 test_done
-- 
2.11.0.483.g087da7b7c-goog
Previous: Brandon WilliamsNext: Brandon Williams
Message 17 of 123 in “decoupling a submodule's existence and its url”
  1. 00/10 decoupling a submodule's existence and its urlBrandon Williams, Feb 23, 2017
  2. 06/10 submodule add: respect submodule.activeBrandon Williams, Feb 23, 2017
  3. 09/10 submodule sync: use submodule--helper is-activeBrandon Williams, Feb 23, 2017
  4. 04/10 completion: clone can initialize specific submodulesBrandon Williams, Feb 23, 2017
  5. 01/10 submodule: decouple url and submodule existenceBrandon Williams, Feb 23, 2017
  6. Junio C HamanoFeb 24, 2017
  7. Brandon WilliamsMar 1, 2017
  8. Stefan BellerMar 1, 2017
  9. Brandon WilliamsMar 6, 2017
  10. Junio C HamanoMar 2, 2017
  11. 03/10 clone: add --submodule-spec=<pathspec> switchBrandon Williams, Feb 23, 2017
  12. 07/10 submodule status: use submodule--helper is-activeBrandon Williams, Feb 23, 2017
  13. 08/10 submodule deinit: use most reliable urlBrandon Williams, Feb 23, 2017
  14. 10/10 submodule--helper clone: check for configured submodules using helperBrandon Williams, Feb 23, 2017
  15. Stefan BellerFeb 24, 2017
  16. Brandon WilliamsFeb 27, 2017
  17. 02/10 submodule update: add `--init-active` switchBrandon Williams, Feb 23, 2017
  18. 05/10 submodule--helper: add is_active commandBrandon Williams, Feb 23, 2017
  19. Stefan BellerFeb 24, 2017
  20. Brandon WilliamsFeb 27, 2017
  21. Stefan BellerFeb 23, 2017
  22. 00/11 decoupling a submodule's existence and its urlBrandon Williams, Mar 9, 2017
  23. 05/11 submodule--helper clone: check for configured submodules using helperBrandon Williams, Mar 9, 2017
  24. 02/11 submodule status: use submodule--helper is-activeBrandon Williams, Mar 9, 2017
  25. 04/11 submodule sync: use submodule--helper is-activeBrandon Williams, Mar 9, 2017
  26. 01/11 submodule--helper: add is_active commandBrandon Williams, Mar 9, 2017
  27. 11/11 submodule add: respect submodule.active and submodule.<name>.activeBrandon Williams, Mar 9, 2017
  28. 06/11 submodule: decouple url and submodule existenceBrandon Williams, Mar 9, 2017
  29. 09/11 completion: clone can initialize specific submodulesBrandon Williams, Mar 9, 2017
  30. 07/11 submodule update: add `--init-active` switchBrandon Williams, Mar 9, 2017
  31. Stefan BellerMar 9, 2017
  32. Brandon WilliamsMar 9, 2017
  33. 08/11 clone: add --submodule-spec=<pathspec> switchBrandon Williams, Mar 9, 2017
  34. 10/11 submodule--helper init: set submodule.<name>.activeBrandon Williams, Mar 9, 2017
  35. Stefan BellerMar 9, 2017
  36. Brandon WilliamsMar 9, 2017
  37. 03/11 submodule deinit: use most reliable urlBrandon Williams, Mar 9, 2017
  38. Stefan BellerMar 9, 2017
  39. Brandon WilliamsMar 9, 2017
  40. 00/10 decoupling a submodule's existence and its urlBrandon Williams, Mar 13, 2017
  41. 01/10 submodule--helper: add is_active commandBrandon Williams, Mar 13, 2017
  42. Stefan BellerMar 13, 2017
  43. Junio C HamanoMar 14, 2017
  44. Brandon WilliamsMar 14, 2017
  45. 02/10 submodule status: use submodule--helper is-activeBrandon Williams, Mar 13, 2017
  46. Junio C HamanoMar 14, 2017
  47. Stefan BellerMar 14, 2017
  48. Junio C HamanoMar 14, 2017
  49. Junio C HamanoMar 14, 2017
  50. Brandon WilliamsMar 14, 2017
  51. Brandon WilliamsMar 14, 2017
  52. 03/10 submodule sync: use submodule--helper is-activeBrandon Williams, Mar 13, 2017
  53. Junio C HamanoMar 14, 2017
  54. Brandon WilliamsMar 14, 2017
  55. 05/10 submodule: decouple url and submodule existenceBrandon Williams, Mar 13, 2017
  56. Stefan BellerMar 13, 2017
  57. Brandon WilliamsMar 15, 2017
  58. Junio C HamanoMar 14, 2017
  59. Junio C HamanoMar 14, 2017
  60. Brandon WilliamsMar 15, 2017
  61. 07/10 clone: add --submodule-spec=<pathspec> switchBrandon Williams, Mar 13, 2017
  62. Junio C HamanoMar 14, 2017
  63. Brandon WilliamsMar 15, 2017
  64. Stefan BellerMar 15, 2017
  65. 08/10 completion: clone can initialize specific submodulesBrandon Williams, Mar 13, 2017
  66. 09/10 submodule--helper init: set submodule.<name>.activeBrandon Williams, Mar 13, 2017
  67. Junio C HamanoMar 14, 2017
  68. Brandon WilliamsMar 15, 2017
  69. Junio C HamanoMar 16, 2017
  70. 04/10 submodule--helper clone: check for configured submodules using helperBrandon Williams, Mar 13, 2017
  71. Junio C HamanoMar 14, 2017
  72. Stefan BellerMar 14, 2017
  73. Junio C HamanoMar 14, 2017
  74. Brandon WilliamsMar 15, 2017
  75. 10/10 submodule add: respect submodule.active and submodule.<name>.activeBrandon Williams, Mar 13, 2017
  76. Junio C HamanoMar 14, 2017
  77. Brandon WilliamsMar 15, 2017
  78. 06/10 submodule update: add `--init-active` switchBrandon Williams, Mar 13, 2017
  79. Junio C HamanoMar 14, 2017
  80. Brandon WilliamsMar 15, 2017
  81. Junio C HamanoMar 14, 2017
  82. Brandon WilliamsMar 15, 2017
  83. Stefan BellerMar 13, 2017
  84. Junio C HamanoMar 14, 2017
  85. Brandon WilliamsMar 14, 2017
  86. 00/10 decoupling url and submodule interestBrandon Williams, Mar 16, 2017
  87. 06/10 submodule: decouple url and submodule interestBrandon Williams, Mar 16, 2017
  88. Stefan BellerMar 16, 2017
  89. 03/10 submodule sync: skip work for inactive submodulesBrandon Williams, Mar 16, 2017
  90. Stefan BellerMar 16, 2017
  91. Brandon WilliamsMar 16, 2017
  92. Stefan BellerMar 16, 2017
  93. Junio C HamanoMar 17, 2017
  94. Brandon WilliamsMar 17, 2017
  95. Junio C HamanoMar 17, 2017
  96. 05/10 submodule--helper clone: check for configured submodules using helperBrandon Williams, Mar 16, 2017
  97. 02/10 submodule status: use submodule--helper is-activeBrandon Williams, Mar 16, 2017
  98. 08/10 clone: teach --recurse-submodules to optionally take a pathspecBrandon Williams, Mar 16, 2017
  99. Stefan BellerMar 17, 2017
  100. Brandon WilliamsMar 17, 2017
  101. 04/10 submodule sync: use submodule--helper is-activeBrandon Williams, Mar 16, 2017
  102. 07/10 submodule init: initialize active submodulesBrandon Williams, Mar 16, 2017
  103. Stefan BellerMar 17, 2017
  104. Brandon WilliamsMar 17, 2017
  105. Stefan BellerMar 17, 2017
  106. 01/10 submodule--helper: add is-active subcommandBrandon Williams, Mar 16, 2017
  107. 10/10 submodule add: respect submodule.active and submodule.<name>.activeBrandon Williams, Mar 16, 2017
  108. 09/10 submodule--helper init: set submodule.<name>.activeBrandon Williams, Mar 16, 2017
  109. Stefan BellerMar 17, 2017
  110. Brandon WilliamsMar 17, 2017
  111. 00/10 decoupling url and submodule interestBrandon Williams, Mar 17, 2017
  112. 06/10 submodule: decouple url and submodule interestBrandon Williams, Mar 17, 2017
  113. 09/10 submodule--helper init: set submodule.<name>.activeBrandon Williams, Mar 17, 2017
  114. 05/10 submodule--helper clone: check for configured submodules using helperBrandon Williams, Mar 17, 2017
  115. 03/10 submodule sync: skip work for inactive submodulesBrandon Williams, Mar 17, 2017
  116. 02/10 submodule status: use submodule--helper is-activeBrandon Williams, Mar 17, 2017
  117. Stefan BellerMar 17, 2017
  118. 08/10 clone: teach --recurse-submodules to optionally take a pathspecBrandon Williams, Mar 17, 2017
  119. 01/10 submodule--helper: add is-active subcommandBrandon Williams, Mar 17, 2017
  120. 07/10 submodule init: initialize active submodulesBrandon Williams, Mar 17, 2017
  121. 04/10 submodule sync: use submodule--helper is-activeBrandon Williams, Mar 17, 2017
  122. 10/10 submodule add: respect submodule.active and submodule.<name>.activeBrandon Williams, Mar 17, 2017
  123. Junio C HamanoMar 18, 2017

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.