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

[PATCH 5/7] Teach git-submodule to use top-level remote when updating subprojects

From
Mark Levedahl <mlevedahl@gmail.com>
Date
Feb 3, 2008, 17:31 UTC
Message-ID
<1202059867-1184-6-git-send-email-mlevedahl@gmail.com>
In-Reply-To
<1202059867-1184-5-git-send-email-mlevedahl@gmail.com>

Modules that are defined using relative urls to the master project are assumed to be completely owned by the project. When running "submodule update" from the top level, it is reasonable that the entire project exists at the remote given by top-level branch.<name>.remote. Using the remote machinery, this remote can be different for each branch and can be different than the current defaults in each submodule.

This teaches submodule to:
1) Possibly define the current master's remote in each submodule, using
the same relative url used by submodule init.
2) Fetch each submodule's updates from the master's remote.

Submodules defined using absolute urls (not relative to the parent) are not touched by this logic. Such modules are assumed to be independent of the master project so submodule can do no better than to fetch from their currently defined default remotes as already done.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
 git-submodule.sh |   20 +++++++++++++++++++-
 1 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index bb0d265..8f31ebe 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -255,6 +255,8 @@ cmd_init()
 
 #
 # Update each submodule path to correct revision, using clone and checkout as needed
+# For owned submodules (defined using relative url), we use master project's remote
+# and define that in each submodule if not already there
 #
 # $@ = requested paths (default to all)
 #
@@ -281,6 +283,7 @@ cmd_update()
 		shift
 	done
 
+	master_remote=$(get_default_remote)
 	git ls-files --stage -- "$@" | grep -e '^160000 ' |
 	while read mode sha1 stage path
 	do
@@ -306,9 +309,24 @@ cmd_update()
 			die "Unable to find current revision in submodule path '$path'"
 		fi
 
+		baseurl="$(GIT_CONFIG=.gitmodules git config submodule."$name".url)"
+		case "$baseurl" in
+		./*|../*)
+			fetch_remote=$master_remote
+			(unset GIT_DIR ; cd "$path" && git config remote."$fetch_remote".url > nul) ||
+			(
+				absurl="$(resolve_relative_url $baseurl)"
+				unset GIT_DIR; cd "$path" && git remote add "$master_remote" "$absurl"
+			) || die "Unable to define remote '$fetch_remote' in submodule path '$path'"
+			;;
+		*)
+			fetch_remote=
+			;;
+		esac
+
 		if test "$subsha1" != "$sha1"
 		then
-			(unset GIT_DIR; cd "$path" && git-fetch &&
+			(unset GIT_DIR; cd "$path" && git-fetch $fetch_remote &&
 				git-checkout -q "$sha1") ||
 			die "Unable to checkout '$sha1' in submodule path '$path'"
 
-- 
1.5.4.18.g43c18
Previous: Mark LevedahlNext: Mark Levedahl
Message 6 of 19 in “[resend] - Improve handling remotes, origin, submodules”
  1. [resend] - Improve handling remotes, origin, submodulesMark Levedahl, Feb 3, 2008
  2. 1/7 Teach remote machinery about core.origin config variableMark Levedahl, Feb 3, 2008
  3. 2/7 git-remote - Unset core.origin when deleting the default remoteMark Levedahl, Feb 3, 2008
  4. 3/7 git-clone - Set remotes.origin config variableMark Levedahl, Feb 3, 2008
  5. 4/7 git-submodule - Possibly inherit parent's default remote on init/cloneMark Levedahl, Feb 3, 2008
  6. 5/7 Teach git-submodule to use top-level remote when updating subprojectsMark Levedahl, Feb 3, 2008
  7. 6/7 git-submodule - Allow adding a submodule in-placeMark Levedahl, Feb 3, 2008
  8. 7/7 Add t/t7401 - test submodule interaction with remotes machineryMark Levedahl, Feb 3, 2008
  9. Johannes SchindelinFeb 3, 2008
  10. Mark LevedahlFeb 4, 2008
  11. Johannes SchindelinFeb 4, 2008
  12. Mark LevedahlFeb 4, 2008
  13. Johannes SchindelinFeb 4, 2008
  14. Junio C HamanoFeb 4, 2008
  15. Johannes SchindelinFeb 4, 2008
  16. Junio C HamanoFeb 4, 2008
  17. Johannes SchindelinFeb 4, 2008
  18. Steffen ProhaskaFeb 4, 2008
  19. Johannes SchindelinFeb 4, 2008

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.