summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorMartin Kelly <mkelly@xevo.com>2017-03-21 16:05:12 -0700
committerMartin Kelly <mkelly@xevo.com>2017-05-23 16:51:31 -0700
commite4e94d26ae81dbc9eb6e2f345fac7cd8c533cb9a (patch)
tree1fe598a2b3e89ae9a56fd640e6cd5b53a8704c7a /project.py
parentffb4b890997b1799f188ec44f005d949feb643a7 (diff)
downloadgit-repo-e4e94d26ae81dbc9eb6e2f345fac7cd8c533cb9a.tar.gz
init: add --submodules to sync manifest submodules
repo sync can sync submodules via the --fetch-submodules option. However, if the manifest repo has submodules, those will not be synced. Having submodules in the manifest repo -- while not commonly done -- can be useful for inheriting a manifest from another project using <include> and layering changes on top of it. In this way, you can avoid having to deal with merge conflicts between your own manifests and the other project's manifests (for example, if you're managing an Android fork). Add a --submodule option to init that automatically syncs the submodules in the manifest repo whenever the manifest repo changes. Change-Id: I45d34f04517774c1462d7f233f482d1d81a332a8 Signed-off-by: Martin Kelly <mkelly@xevo.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py49
1 files changed, 41 insertions, 8 deletions
diff --git a/project.py b/project.py
index 0d60fc6e..e3185b88 100644
--- a/project.py
+++ b/project.py
@@ -1198,7 +1198,8 @@ class Project(object):
1198 no_tags=False, 1198 no_tags=False,
1199 archive=False, 1199 archive=False,
1200 optimized_fetch=False, 1200 optimized_fetch=False,
1201 prune=False): 1201 prune=False,
1202 submodules=False):
1202 """Perform only the network IO portion of the sync process. 1203 """Perform only the network IO portion of the sync process.
1203 Local working directory/branch state is not affected. 1204 Local working directory/branch state is not affected.
1204 """ 1205 """
@@ -1275,7 +1276,8 @@ class Project(object):
1275 if (need_to_fetch and 1276 if (need_to_fetch and
1276 not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir, 1277 not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir,
1277 current_branch_only=current_branch_only, 1278 current_branch_only=current_branch_only,
1278 no_tags=no_tags, prune=prune, depth=depth)): 1279 no_tags=no_tags, prune=prune, depth=depth,
1280 submodules=submodules)):
1279 return False 1281 return False
1280 1282
1281 if self.worktree: 1283 if self.worktree:
@@ -1331,11 +1333,11 @@ class Project(object):
1331 raise ManifestInvalidRevisionError('revision %s in %s not found' % 1333 raise ManifestInvalidRevisionError('revision %s in %s not found' %
1332 (self.revisionExpr, self.name)) 1334 (self.revisionExpr, self.name))
1333 1335
1334 def Sync_LocalHalf(self, syncbuf, force_sync=False): 1336 def Sync_LocalHalf(self, syncbuf, force_sync=False, submodules=False):
1335 """Perform only the local IO portion of the sync process. 1337 """Perform only the local IO portion of the sync process.
1336 Network access is not required. 1338 Network access is not required.
1337 """ 1339 """
1338 self._InitWorkTree(force_sync=force_sync) 1340 self._InitWorkTree(force_sync=force_sync, submodules=submodules)
1339 all_refs = self.bare_ref.all 1341 all_refs = self.bare_ref.all
1340 self.CleanPublishedCache(all_refs) 1342 self.CleanPublishedCache(all_refs)
1341 revid = self.GetRevisionId(all_refs) 1343 revid = self.GetRevisionId(all_refs)
@@ -1344,6 +1346,9 @@ class Project(object):
1344 self._FastForward(revid) 1346 self._FastForward(revid)
1345 self._CopyAndLinkFiles() 1347 self._CopyAndLinkFiles()
1346 1348
1349 def _dosubmodules():
1350 self._SyncSubmodules(quiet=True)
1351
1347 head = self.work_git.GetHead() 1352 head = self.work_git.GetHead()
1348 if head.startswith(R_HEADS): 1353 if head.startswith(R_HEADS):
1349 branch = head[len(R_HEADS):] 1354 branch = head[len(R_HEADS):]
@@ -1377,6 +1382,8 @@ class Project(object):
1377 1382
1378 try: 1383 try:
1379 self._Checkout(revid, quiet=True) 1384 self._Checkout(revid, quiet=True)
1385 if submodules:
1386 self._SyncSubmodules(quiet=True)
1380 except GitError as e: 1387 except GitError as e:
1381 syncbuf.fail(self, e) 1388 syncbuf.fail(self, e)
1382 return 1389 return
@@ -1401,6 +1408,8 @@ class Project(object):
1401 branch.name) 1408 branch.name)
1402 try: 1409 try:
1403 self._Checkout(revid, quiet=True) 1410 self._Checkout(revid, quiet=True)
1411 if submodules:
1412 self._SyncSubmodules(quiet=True)
1404 except GitError as e: 1413 except GitError as e:
1405 syncbuf.fail(self, e) 1414 syncbuf.fail(self, e)
1406 return 1415 return
@@ -1426,6 +1435,8 @@ class Project(object):
1426 # strict subset. We can fast-forward safely. 1435 # strict subset. We can fast-forward safely.
1427 # 1436 #
1428 syncbuf.later1(self, _doff) 1437 syncbuf.later1(self, _doff)
1438 if submodules:
1439 syncbuf.later1(self, _dosubmodules)
1429 return 1440 return
1430 1441
1431 # Examine the local commits not in the remote. Find the 1442 # Examine the local commits not in the remote. Find the
@@ -1477,19 +1488,28 @@ class Project(object):
1477 branch.Save() 1488 branch.Save()
1478 1489
1479 if cnt_mine > 0 and self.rebase: 1490 if cnt_mine > 0 and self.rebase:
1491 def _docopyandlink():
1492 self._CopyAndLinkFiles()
1493
1480 def _dorebase(): 1494 def _dorebase():
1481 self._Rebase(upstream='%s^1' % last_mine, onto=revid) 1495 self._Rebase(upstream='%s^1' % last_mine, onto=revid)
1482 self._CopyAndLinkFiles()
1483 syncbuf.later2(self, _dorebase) 1496 syncbuf.later2(self, _dorebase)
1497 if submodules:
1498 syncbuf.later2(self, _dosubmodules)
1499 syncbuf.later2(self, _docopyandlink)
1484 elif local_changes: 1500 elif local_changes:
1485 try: 1501 try:
1486 self._ResetHard(revid) 1502 self._ResetHard(revid)
1503 if submodules:
1504 self._SyncSubmodules(quiet=True)
1487 self._CopyAndLinkFiles() 1505 self._CopyAndLinkFiles()
1488 except GitError as e: 1506 except GitError as e:
1489 syncbuf.fail(self, e) 1507 syncbuf.fail(self, e)
1490 return 1508 return
1491 else: 1509 else:
1492 syncbuf.later1(self, _doff) 1510 syncbuf.later1(self, _doff)
1511 if submodules:
1512 syncbuf.later1(self, _dosubmodules)
1493 1513
1494 def AddCopyFile(self, src, dest, absdest): 1514 def AddCopyFile(self, src, dest, absdest):
1495 # dest should already be an absolute path, but src is project relative 1515 # dest should already be an absolute path, but src is project relative
@@ -1892,7 +1912,8 @@ class Project(object):
1892 alt_dir=None, 1912 alt_dir=None,
1893 no_tags=False, 1913 no_tags=False,
1894 prune=False, 1914 prune=False,
1895 depth=None): 1915 depth=None,
1916 submodules=False):
1896 1917
1897 is_sha1 = False 1918 is_sha1 = False
1898 tag_name = None 1919 tag_name = None
@@ -2004,6 +2025,9 @@ class Project(object):
2004 if prune: 2025 if prune:
2005 cmd.append('--prune') 2026 cmd.append('--prune')
2006 2027
2028 if submodules:
2029 cmd.append('--recurse-submodules=on-demand')
2030
2007 spec = [] 2031 spec = []
2008 if not current_branch_only: 2032 if not current_branch_only:
2009 # Fetch whole repo 2033 # Fetch whole repo
@@ -2224,6 +2248,13 @@ class Project(object):
2224 if GitCommand(self, cmd).Wait() != 0: 2248 if GitCommand(self, cmd).Wait() != 0:
2225 raise GitError('%s reset --hard %s ' % (self.name, rev)) 2249 raise GitError('%s reset --hard %s ' % (self.name, rev))
2226 2250
2251 def _SyncSubmodules(self, quiet=True):
2252 cmd = ['submodule', 'update', '--init', '--recursive']
2253 if quiet:
2254 cmd.append('-q')
2255 if GitCommand(self, cmd).Wait() != 0:
2256 raise GitError('%s submodule update --init --recursive %s ' % self.name)
2257
2227 def _Rebase(self, upstream, onto=None): 2258 def _Rebase(self, upstream, onto=None):
2228 cmd = ['rebase'] 2259 cmd = ['rebase']
2229 if onto is not None: 2260 if onto is not None:
@@ -2464,7 +2495,7 @@ class Project(object):
2464 else: 2495 else:
2465 raise 2496 raise
2466 2497
2467 def _InitWorkTree(self, force_sync=False): 2498 def _InitWorkTree(self, force_sync=False, submodules=False):
2468 dotgit = os.path.join(self.worktree, '.git') 2499 dotgit = os.path.join(self.worktree, '.git')
2469 init_dotgit = not os.path.exists(dotgit) 2500 init_dotgit = not os.path.exists(dotgit)
2470 try: 2501 try:
@@ -2479,7 +2510,7 @@ class Project(object):
2479 if force_sync: 2510 if force_sync:
2480 try: 2511 try:
2481 shutil.rmtree(dotgit) 2512 shutil.rmtree(dotgit)
2482 return self._InitWorkTree(force_sync=False) 2513 return self._InitWorkTree(force_sync=False, submodules=submodules)
2483 except: 2514 except:
2484 raise e 2515 raise e
2485 raise e 2516 raise e
@@ -2493,6 +2524,8 @@ class Project(object):
2493 if GitCommand(self, cmd).Wait() != 0: 2524 if GitCommand(self, cmd).Wait() != 0:
2494 raise GitError("cannot initialize work tree") 2525 raise GitError("cannot initialize work tree")
2495 2526
2527 if submodules:
2528 self._SyncSubmodules(quiet=True)
2496 self._CopyAndLinkFiles() 2529 self._CopyAndLinkFiles()
2497 except Exception: 2530 except Exception:
2498 if init_dotgit: 2531 if init_dotgit: