Skip to content

Commit 99eca45

Browse files
committed
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 <kaushikl@qti.qualcomm.com> Reviewed-by: Nasser Grainawi <nasser.grainawi@oss.qualcomm.com> Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> Reviewed-by: Mike Frysinger <vapier@google.com>
1 parent 66685f0 commit 99eca45

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

project.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ def __init__(
642642
# project containing repo hooks.
643643
self.enabled_repo_hooks = []
644644

645+
# This will be updated later if the project has submodules and
646+
# if they will be synced.
647+
self.has_subprojects = False
648+
645649
def RelPath(self, local=True):
646650
"""Return the path for the project relative to a manifest.
647651
@@ -1560,6 +1564,11 @@ def fail(error: Exception):
15601564
return
15611565

15621566
self._InitWorkTree(force_sync=force_sync, submodules=submodules)
1567+
# TODO(https://git-scm.com/docs/git-worktree#_bugs): Re-evaluate if
1568+
# submodules can be init when using worktrees once its support is
1569+
# complete.
1570+
if self.has_subprojects and not self.use_git_worktrees:
1571+
self._InitSubmodules()
15631572
all_refs = self.bare_ref.all
15641573
self.CleanPublishedCache(all_refs)
15651574
revid = self.GetRevisionId(all_refs)
@@ -2347,6 +2356,8 @@ def GetDerivedSubprojects(self):
23472356
)
23482357
result.append(subproject)
23492358
result.extend(subproject.GetDerivedSubprojects())
2359+
if result:
2360+
self.has_subprojects = True
23502361
return result
23512362

23522363
def EnableRepositoryExtension(self, key, value="true", version=1):
@@ -2997,6 +3008,17 @@ def _SyncSubmodules(self, quiet=True):
29973008
project=self.name,
29983009
)
29993010

3011+
def _InitSubmodules(self, quiet=True):
3012+
"""Initialize the submodules for the project."""
3013+
cmd = ["submodule", "init"]
3014+
if quiet:
3015+
cmd.append("-q")
3016+
if GitCommand(self, cmd).Wait() != 0:
3017+
raise GitError(
3018+
f"{self.name} submodule init",
3019+
project=self.name,
3020+
)
3021+
30003022
def _Rebase(self, upstream, onto=None):
30013023
cmd = ["rebase"]
30023024
if onto is not None:

0 commit comments

Comments
 (0)