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

[PATCH 1/2] Teach --recursive to submodule sync

From
Phil Hord <hordp@cisco.com>
Date
Oct 23, 2012, 23:15 UTC
Message-ID
<1351034141-2641-2-git-send-email-hordp@cisco.com>
In-Reply-To
<1351034141-2641-1-git-send-email-hordp@cisco.com>

The submodule sync command was somehow left out when --recursive was added to the other submodule commands.

Teach sync to handle the --recursive switch by recursing when we're in a submodule we are sync'ing.

Change the report during sync to show submodule-path instead of submodule-name to be consistent with the other submodule commands and to help recursed paths make sense.

Signed-off-by: Phil Hord <hordp@cisco.com>
---
 git-submodule.sh | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index ab6b110..6dd2338 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -11,7 +11,7 @@ USAGE="[--quiet] add [-b branch] [-f|--force] [--reference <repository>] [--] <r
    or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
-   or: $dashless [--quiet] sync [--] [<path>...]"
+   or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
 OPTIONS_SPEC=
 . git-sh-setup
 . git-sh-i18n
@@ -1008,7 +1008,9 @@ cmd_sync()
 		case "$1" in
 		-q|--quiet)
 			GIT_QUIET=1
-			shift
+			;;
+		--recursive)
+			recursive=1
 			;;
 		--)
 			shift
@@ -1021,6 +1023,8 @@ cmd_sync()
 			break
 			;;
 		esac
+		orig_flags="$orig_flags $(git rev-parse --sq-quote "$1")"
+		shift
 	done
 	cd_to_toplevel
 	module_list "$@" |
@@ -1051,7 +1055,7 @@ cmd_sync()
 
 		if git config "submodule.$name.url" >/dev/null 2>/dev/null
 		then
-			say "$(eval_gettext "Synchronizing submodule url for '\$name'")"
+			say "$(eval_gettext "Synchronizing submodule url for '\$prefix\$sm_path'")"
 			git config submodule."$name".url "$super_config_url"
 
 			if test -e "$sm_path"/.git
@@ -1061,6 +1065,14 @@ cmd_sync()
 				cd "$sm_path"
 				remote=$(get_default_remote)
 				git config remote."$remote".url "$sub_origin_url"
+
+				if test -n "$recursive"
+				then
+				(
+					prefix="$prefix$sm_path/"
+					eval cmd_sync "$orig_args"
+				)
+			fi
 			)
 			fi
 		fi
-- 
1.8.0.2.gcde19fc.dirty
Previous: Phil HordNext: Jens Lehmann
Message 4 of 12 in “git submodule sync --recursive”
  1. Phil HordOct 16, 2012
  2. Jens LehmannOct 17, 2012
  3. Phil HordOct 23, 2012
  4. 1/2 Teach --recursive to submodule syncPhil Hord, Oct 23, 2012
  5. Jens LehmannOct 25, 2012
  6. Phil HordOct 26, 2012
  7. Phil HordOct 26, 2012
  8. Jens LehmannOct 26, 2012
  9. 0/2 Reroll submodule sync --recursivePhil Hord, Oct 26, 2012
  10. 1/2 Teach --recursive to submodule syncPhil Hord, Oct 26, 2012
  11. 2/2 Add tests for submodule sync --recursivePhil Hord, Oct 26, 2012
  12. 2/2 Add tests for submodule sync --recursivePhil Hord, Oct 23, 2012

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.