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: