From 99eca45eb2d578cd853bc5b0bf83f7b175e60b72 Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Tue, 17 Dec 2024 15:16:39 -0800 Subject: [PATCH] Activate submodules This change moves further towards ensuring Git can understand repo's submodules. 'submodule init' is used to make the submodules active[1]. [1] https://git-scm.com/docs/gitsubmodules#_active_submodules Change-Id: I0c20ff1991101fc5be171e566d8fb644aab47200 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/446182 Tested-by: Kaushik Lingarkar Reviewed-by: Nasser Grainawi Reviewed-by: Josip Sokcevic Reviewed-by: Mike Frysinger --- project.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/project.py b/project.py index 37cec98f..53350b7f 100644 --- a/project.py +++ b/project.py @@ -642,6 +642,10 @@ class Project: # project containing repo hooks. self.enabled_repo_hooks = [] + # This will be updated later if the project has submodules and + # if they will be synced. + self.has_subprojects = False + def RelPath(self, local=True): """Return the path for the project relative to a manifest. @@ -1560,6 +1564,11 @@ class Project: return self._InitWorkTree(force_sync=force_sync, submodules=submodules) + # TODO(https://git-scm.com/docs/git-worktree#_bugs): Re-evaluate if + # submodules can be init when using worktrees once its support is + # complete. + if self.has_subprojects and not self.use_git_worktrees: + self._InitSubmodules() all_refs = self.bare_ref.all self.CleanPublishedCache(all_refs) revid = self.GetRevisionId(all_refs) @@ -2347,6 +2356,8 @@ class Project: ) result.append(subproject) result.extend(subproject.GetDerivedSubprojects()) + if result: + self.has_subprojects = True return result def EnableRepositoryExtension(self, key, value="true", version=1): @@ -2997,6 +3008,17 @@ class Project: project=self.name, ) + def _InitSubmodules(self, quiet=True): + """Initialize the submodules for the project.""" + cmd = ["submodule", "init"] + if quiet: + cmd.append("-q") + if GitCommand(self, cmd).Wait() != 0: + raise GitError( + f"{self.name} submodule init", + project=self.name, + ) + def _Rebase(self, upstream, onto=None): cmd = ["rebase"] if onto is not None: