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

[RFC/PATCH 1/4] submodules: implement synchronizing of remotes.

From
Patrick Steinhardt <ps@pks.im>
Date
Apr 8, 2015, 10:58 UTC
Message-ID
<1428490705-11586-2-git-send-email-ps@pks.im>
In-Reply-To
<1428490705-11586-1-git-send-email-ps@pks.im>

Previously it was not possible to specify custom remotes for submodules. This feature has now been implemented and can be accessed by setting the keys 'submodule-remote.$name.$remote.url' and 'submodule-remote.$name.$remote.push-url', respectively.

When issuing a `git submodule sync` we will test if submodules
have one or more remotes specified and if so those will be either
added if nonexistent or their URLs will be adjusted to match the
specified URLs.
---
 git-submodule.sh | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)
diff --git a/git-submodule.sh b/git-submodule.sh
index 36797c3..599a847 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -1268,6 +1268,7 @@ cmd_status()
 		fi
 	done
 }
+
 #
 # Sync remote urls for submodules
 # This makes the value for remote.$remote.url match the value
@@ -1347,6 +1348,32 @@ cmd_sync()
 			)
 			fi
 		fi
+
+		git config -f .gitmodules --get-regexp "submodule-remote\.$name\..*\.url" 2>/dev/null |
+		while read key url
+		do
+			remote=$(echo "$key" | sed "s/submodule-remote\.$name\.\(.*\)\.url/\1/")
+			pushurl=$(git config -f .gitmodules --get "submodule-remote.$name.$remote.pushurl")
+
+			(
+				cd "$sm_path"
+
+				if ! git remote | grep "^$remote$" >/dev/null 2>/dev/null
+				then
+					say "$(eval_gettext "Adding remote '$remote' for submodule '$prefix$sm_path'")"
+					git remote add "$remote" "$url"
+				else
+					say "$(eval_gettext "Setting URL for remote '$remote' in submodule '$prefix$sm_path'")"
+					git remote set-url "$remote" "$url"
+				fi
+
+				if test ! -z "$pushurl"
+				then
+					say "$(eval_gettext "Setting push URL for remote '$remote' in submodule '$prefix$sm_path'")"
+					git remote set-url --push "$remote" "$pushurl"
+				fi
+			)
+		done
 	done
 }
 
-- 
2.3.5
Previous: Patrick SteinhardtNext: Junio C Hamano
Message 2 of 7 in “submodule remotes”
  1. 0/4 submodule remotesPatrick Steinhardt, Apr 8, 2015
  2. 1/4 submodules: implement synchronizing of remotes.Patrick Steinhardt, Apr 8, 2015
  3. Junio C HamanoApr 8, 2015
  4. Patrick SteinhardtApr 9, 2015
  5. 2/4 submodules: implement remote commands.Patrick Steinhardt, Apr 8, 2015
  6. 3/4 submodules: update docs to reflect remotes.Patrick Steinhardt, Apr 8, 2015
  7. 4/4 submodules: add bash completion for remotes.Patrick Steinhardt, Apr 8, 2015

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.