diff options
-rw-r--r-- | git_superproject.py | 37 |
1 files changed, 29 insertions, 8 deletions
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 | |||
27 | 27 | ||
28 | from error import GitError | 28 | from error import GitError |
29 | from git_command import GitCommand | 29 | from git_command import GitCommand |
30 | import platform_utils | ||
31 | 30 | ||
32 | 31 | ||
33 | class Superproject(object): | 32 | class Superproject(object): |
@@ -63,7 +62,8 @@ class Superproject(object): | |||
63 | Returns: | 62 | Returns: |
64 | True if 'git clone <url> <branch>' is successful, or False. | 63 | True if 'git clone <url> <branch>' is successful, or False. |
65 | """ | 64 | """ |
66 | cmd = ['clone', url, '--depth', '1'] | 65 | os.mkdir(self._superproject_path) |
66 | cmd = ['clone', url, '--filter', 'blob:none'] | ||
67 | if branch: | 67 | if branch: |
68 | cmd += ['--branch', branch] | 68 | cmd += ['--branch', branch] |
69 | p = GitCommand(None, | 69 | p = GitCommand(None, |
@@ -80,6 +80,28 @@ class Superproject(object): | |||
80 | return False | 80 | return False |
81 | return True | 81 | return True |
82 | 82 | ||
83 | def _Pull(self): | ||
84 | """Do a 'git pull' to to fetch the latest content. | ||
85 | |||
86 | Returns: | ||
87 | True if 'git pull <branch>' is successful, or False. | ||
88 | """ | ||
89 | git_dir = os.path.join(self._superproject_path, 'superproject') | ||
90 | if not os.path.exists(git_dir): | ||
91 | raise GitError('git pull. Missing drectory: %s' % git_dir) | ||
92 | cmd = ['pull'] | ||
93 | p = GitCommand(None, | ||
94 | cmd, | ||
95 | cwd=git_dir, | ||
96 | capture_stdout=True, | ||
97 | capture_stderr=True) | ||
98 | retval = p.Wait() | ||
99 | if retval: | ||
100 | print('repo: error: git pull call failed with return code: %r, stderr: %r' % | ||
101 | (retval, p.stderr), file=sys.stderr) | ||
102 | return False | ||
103 | return True | ||
104 | |||
83 | def _LsTree(self): | 105 | def _LsTree(self): |
84 | """Returns the data from 'git ls-tree -r HEAD'. | 106 | """Returns the data from 'git ls-tree -r HEAD'. |
85 | 107 | ||
@@ -121,12 +143,11 @@ class Superproject(object): | |||
121 | if not url: | 143 | if not url: |
122 | raise ValueError('url argument is not supplied.') | 144 | raise ValueError('url argument is not supplied.') |
123 | if os.path.exists(self._superproject_path): | 145 | if os.path.exists(self._superproject_path): |
124 | platform_utils.rmtree(self._superproject_path) | 146 | if not self._Pull(): |
125 | os.mkdir(self._superproject_path) | 147 | raise GitError('git pull failed for url: %s' % url) |
126 | 148 | else: | |
127 | # TODO(rtenneti): we shouldn't be cloning the repo from scratch every time. | 149 | if not self._Clone(url, branch): |
128 | if not self._Clone(url, branch): | 150 | raise GitError('git clone failed for url: %s' % url) |
129 | raise GitError('git clone failed for url: %s' % url) | ||
130 | 151 | ||
131 | data = self._LsTree() | 152 | data = self._LsTree() |
132 | if not data: | 153 | if not data: |