sync: Added --filter=blob:none (and no-depth) wduring git clone of superproject.
Tested the code with the following commands.
$ ./run_tests -v tests/test_git_superproject.py
$ ./run_tests -v
Tested the sync code by copying all the repo changes into my Android
AOSP checkout and doing a repo sync --use-superproject twice.
.../WORKING_DIRECTORY$ repo sync --use-superproject
Bug: https://crbug.com/gerrit/13709
Bug: https://crbug.com/gerrit/13707
Tested-by: Raman Tenneti <rtenneti@google.com>
Change-Id: Ieea31445ca89ba1d217e779ec7a7a2ebe81ac518
diff --git a/git_superproject.py b/git_superproject.py
index 3e87e92..e2045cf 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -27,7 +27,6 @@
from error import GitError
from git_command import GitCommand
-import platform_utils
class Superproject(object):
@@ -63,7 +62,8 @@
Returns:
True if 'git clone <url> <branch>' 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 @@
return False
return True
+ def _Pull(self):
+ """Do a 'git pull' to to fetch the latest content.
+
+ Returns:
+ True if 'git pull <branch>' 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 @@
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: