Merge "init: add --submodules to sync manifest submodules"

This commit is contained in:
David Pursehouse
2017-05-27 04:24:58 +00:00
committed by Gerrit Code Review
5 changed files with 59 additions and 12 deletions

View File

@@ -1198,7 +1198,8 @@ class Project(object):
no_tags=False,
archive=False,
optimized_fetch=False,
prune=False):
prune=False,
submodules=False):
"""Perform only the network IO portion of the sync process.
Local working directory/branch state is not affected.
"""
@@ -1275,7 +1276,8 @@ class Project(object):
if (need_to_fetch and
not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir,
current_branch_only=current_branch_only,
no_tags=no_tags, prune=prune, depth=depth)):
no_tags=no_tags, prune=prune, depth=depth,
submodules=submodules)):
return False
if self.worktree:
@@ -1331,11 +1333,11 @@ class Project(object):
raise ManifestInvalidRevisionError('revision %s in %s not found' %
(self.revisionExpr, self.name))
def Sync_LocalHalf(self, syncbuf, force_sync=False):
def Sync_LocalHalf(self, syncbuf, force_sync=False, submodules=False):
"""Perform only the local IO portion of the sync process.
Network access is not required.
"""
self._InitWorkTree(force_sync=force_sync)
self._InitWorkTree(force_sync=force_sync, submodules=submodules)
all_refs = self.bare_ref.all
self.CleanPublishedCache(all_refs)
revid = self.GetRevisionId(all_refs)
@@ -1344,6 +1346,9 @@ class Project(object):
self._FastForward(revid)
self._CopyAndLinkFiles()
def _dosubmodules():
self._SyncSubmodules(quiet=True)
head = self.work_git.GetHead()
if head.startswith(R_HEADS):
branch = head[len(R_HEADS):]
@@ -1377,6 +1382,8 @@ class Project(object):
try:
self._Checkout(revid, quiet=True)
if submodules:
self._SyncSubmodules(quiet=True)
except GitError as e:
syncbuf.fail(self, e)
return
@@ -1401,6 +1408,8 @@ class Project(object):
branch.name)
try:
self._Checkout(revid, quiet=True)
if submodules:
self._SyncSubmodules(quiet=True)
except GitError as e:
syncbuf.fail(self, e)
return
@@ -1426,6 +1435,8 @@ class Project(object):
# strict subset. We can fast-forward safely.
#
syncbuf.later1(self, _doff)
if submodules:
syncbuf.later1(self, _dosubmodules)
return
# Examine the local commits not in the remote. Find the
@@ -1477,19 +1488,28 @@ class Project(object):
branch.Save()
if cnt_mine > 0 and self.rebase:
def _docopyandlink():
self._CopyAndLinkFiles()
def _dorebase():
self._Rebase(upstream='%s^1' % last_mine, onto=revid)
self._CopyAndLinkFiles()
syncbuf.later2(self, _dorebase)
if submodules:
syncbuf.later2(self, _dosubmodules)
syncbuf.later2(self, _docopyandlink)
elif local_changes:
try:
self._ResetHard(revid)
if submodules:
self._SyncSubmodules(quiet=True)
self._CopyAndLinkFiles()
except GitError as e:
syncbuf.fail(self, e)
return
else:
syncbuf.later1(self, _doff)
if submodules:
syncbuf.later1(self, _dosubmodules)
def AddCopyFile(self, src, dest, absdest):
# dest should already be an absolute path, but src is project relative
@@ -1892,7 +1912,8 @@ class Project(object):
alt_dir=None,
no_tags=False,
prune=False,
depth=None):
depth=None,
submodules=False):
is_sha1 = False
tag_name = None
@@ -2006,6 +2027,9 @@ class Project(object):
if prune:
cmd.append('--prune')
if submodules:
cmd.append('--recurse-submodules=on-demand')
spec = []
if not current_branch_only:
# Fetch whole repo
@@ -2226,6 +2250,13 @@ class Project(object):
if GitCommand(self, cmd).Wait() != 0:
raise GitError('%s reset --hard %s ' % (self.name, rev))
def _SyncSubmodules(self, quiet=True):
cmd = ['submodule', 'update', '--init', '--recursive']
if quiet:
cmd.append('-q')
if GitCommand(self, cmd).Wait() != 0:
raise GitError('%s submodule update --init --recursive %s ' % self.name)
def _Rebase(self, upstream, onto=None):
cmd = ['rebase']
if onto is not None:
@@ -2466,7 +2497,7 @@ class Project(object):
else:
raise
def _InitWorkTree(self, force_sync=False):
def _InitWorkTree(self, force_sync=False, submodules=False):
dotgit = os.path.join(self.worktree, '.git')
init_dotgit = not os.path.exists(dotgit)
try:
@@ -2481,7 +2512,7 @@ class Project(object):
if force_sync:
try:
shutil.rmtree(dotgit)
return self._InitWorkTree(force_sync=False)
return self._InitWorkTree(force_sync=False, submodules=submodules)
except:
raise e
raise e
@@ -2495,6 +2526,8 @@ class Project(object):
if GitCommand(self, cmd).Wait() != 0:
raise GitError("cannot initialize work tree")
if submodules:
self._SyncSubmodules(quiet=True)
self._CopyAndLinkFiles()
except Exception:
if init_dotgit: