From 619ff0b697869eb495ad807f2e4faace251d243d Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Wed, 10 Sep 2025 17:07:35 -0700 Subject: [PATCH] Fix submodule initialization in interleaved sync mode With the introduction of interleaved sync mode, the submodule activation logic broke because the 'has_submodules' attribute was no longer being populated when needed. With this change, each submodule is initialized when it enters the Sync_LocalHalf stage, whereas previously all submodules were initialized at once when the parent repository entered the Sync_LocalHalf stage. This change makes the submodule activation logic more robust and less prone to breakage. Change-Id: I25eca4ea2a6868219045cfa088988eb01ded47d2 --- project.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/project.py b/project.py index 8d18e2506..80d5a98ec 100644 --- a/project.py +++ b/project.py @@ -642,10 +642,6 @@ 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. @@ -1563,8 +1559,8 @@ class Project: # 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() + if self.parent and not self.use_git_worktrees: + self._InitSubmodule() all_refs = self.bare_ref.all self.CleanPublishedCache(all_refs) revid = self.GetRevisionId(all_refs) @@ -2359,8 +2355,6 @@ 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): @@ -3026,14 +3020,22 @@ class Project: project=self.name, ) - def _InitSubmodules(self, quiet=True): - """Initialize the submodules for the project.""" + def _InitSubmodule(self, quiet=True): + """Initialize the submodule.""" cmd = ["submodule", "init"] if quiet: cmd.append("-q") - if GitCommand(self, cmd).Wait() != 0: + cmd.append(self.worktree) + if ( + GitCommand( + None, + cmd, + cwd=self.parent.worktree, + ).Wait() + != 0 + ): raise GitError( - f"{self.name} submodule init", + f"{self.parent.name} submodule init {self.worktree}", project=self.name, )