@@ -642,6 +642,10 @@ def __init__(
642
642
# project containing repo hooks.
643
643
self .enabled_repo_hooks = []
644
644
645
+ # This will be updated later if the project has submodules and
646
+ # if they will be synced.
647
+ self .has_subprojects = False
648
+
645
649
def RelPath (self , local = True ):
646
650
"""Return the path for the project relative to a manifest.
647
651
@@ -1560,6 +1564,11 @@ def fail(error: Exception):
1560
1564
return
1561
1565
1562
1566
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 ()
1563
1572
all_refs = self .bare_ref .all
1564
1573
self .CleanPublishedCache (all_refs )
1565
1574
revid = self .GetRevisionId (all_refs )
@@ -2347,6 +2356,8 @@ def GetDerivedSubprojects(self):
2347
2356
)
2348
2357
result .append (subproject )
2349
2358
result .extend (subproject .GetDerivedSubprojects ())
2359
+ if result :
2360
+ self .has_subprojects = True
2350
2361
return result
2351
2362
2352
2363
def EnableRepositoryExtension (self , key , value = "true" , version = 1 ):
@@ -2997,6 +3008,17 @@ def _SyncSubmodules(self, quiet=True):
2997
3008
project = self .name ,
2998
3009
)
2999
3010
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
+
3000
3022
def _Rebase (self , upstream , onto = None ):
3001
3023
cmd = ["rebase" ]
3002
3024
if onto is not None :
0 commit comments