diff --git a/git_superproject.py b/git_superproject.py index 3e87e929..e2045cfd 100644 --- a/git_superproject.py +++ b/git_superproject.py @@ -27,7 +27,6 @@ import sys from error import GitError from git_command import GitCommand -import platform_utils class Superproject(object): @@ -63,7 +62,8 @@ class Superproject(object): Returns: True if 'git clone ' is successful, or False. """ - cmd = ['clone', url, '--depth', '1'] + os.mkdir(self._superproject_path) + cmd = ['clone', url, '--filter', 'blob:none'] if branch: cmd += ['--branch', branch] p = GitCommand(None, @@ -80,6 +80,28 @@ class Superproject(object): return False return True + def _Pull(self): + """Do a 'git pull' to to fetch the latest content. + + Returns: + True if 'git pull ' is successful, or False. + """ + git_dir = os.path.join(self._superproject_path, 'superproject') + if not os.path.exists(git_dir): + raise GitError('git pull. Missing drectory: %s' % git_dir) + cmd = ['pull'] + p = GitCommand(None, + cmd, + cwd=git_dir, + capture_stdout=True, + capture_stderr=True) + retval = p.Wait() + if retval: + print('repo: error: git pull call failed with return code: %r, stderr: %r' % + (retval, p.stderr), file=sys.stderr) + return False + return True + def _LsTree(self): """Returns the data from 'git ls-tree -r HEAD'. @@ -121,12 +143,11 @@ class Superproject(object): if not url: raise ValueError('url argument is not supplied.') if os.path.exists(self._superproject_path): - platform_utils.rmtree(self._superproject_path) - os.mkdir(self._superproject_path) - - # TODO(rtenneti): we shouldn't be cloning the repo from scratch every time. - if not self._Clone(url, branch): - raise GitError('git clone failed for url: %s' % url) + if not self._Pull(): + raise GitError('git pull failed for url: %s' % url) + else: + if not self._Clone(url, branch): + raise GitError('git clone failed for url: %s' % url) data = self._LsTree() if not data: