OLD | NEW |
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 import itertools | 5 import itertools |
6 import re | 6 import re |
7 | 7 |
8 from recipe_engine import recipe_api | 8 from recipe_engine import recipe_api |
9 | 9 |
10 class GitApi(recipe_api.RecipeApi): | 10 class GitApi(recipe_api.RecipeApi): |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 a side effect of all stderr output of 'git fetch' going to that file. | 133 a side effect of all stderr output of 'git fetch' going to that file. |
134 can_fail_build (bool): if False, ignore errors during fetch or checkout. | 134 can_fail_build (bool): if False, ignore errors during fetch or checkout. |
135 set_got_revision (bool): if True, resolves HEAD and sets got_revision | 135 set_got_revision (bool): if True, resolves HEAD and sets got_revision |
136 property. | 136 property. |
137 remote_name (str): name of the git remote to use | 137 remote_name (str): name of the git remote to use |
138 display_fetch_size (bool): if True, run `git count-objects` before and | 138 display_fetch_size (bool): if True, run `git count-objects` before and |
139 after fetch and display delta. Adds two more steps. Defaults to False. | 139 after fetch and display delta. Adds two more steps. Defaults to False. |
140 file_name (str): optional path to a single file to checkout. | 140 file_name (str): optional path to a single file to checkout. |
141 submodule_update_recursive (bool): if True, updates submodules | 141 submodule_update_recursive (bool): if True, updates submodules |
142 recursively. | 142 recursively. |
| 143 |
| 144 Returns: If the checkout was successful, this returns the commit hash of |
| 145 the checked-out-repo. Otherwise this returns None. |
143 """ | 146 """ |
| 147 retVal = None |
| 148 |
144 # TODO(robertocn): Break this function and refactor calls to it. | 149 # TODO(robertocn): Break this function and refactor calls to it. |
145 # The problem is that there are way too many unrealated use cases for | 150 # The problem is that there are way too many unrealated use cases for |
146 # it, and the function's signature is getting unwieldy and its body | 151 # it, and the function's signature is getting unwieldy and its body |
147 # unreadable. | 152 # unreadable. |
148 display_fetch_size = display_fetch_size or False | 153 display_fetch_size = display_fetch_size or False |
149 if not dir_path: | 154 if not dir_path: |
150 dir_path = url.rsplit('/', 1)[-1] | 155 dir_path = url.rsplit('/', 1)[-1] |
151 if dir_path.endswith('.git'): # ex: https://host/foobar.git | 156 if dir_path.endswith('.git'): # ex: https://host/foobar.git |
152 dir_path = dir_path[:-len('.git')] | 157 dir_path = dir_path[:-len('.git')] |
153 | 158 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 cwd=dir_path, | 245 cwd=dir_path, |
241 name='git checkout%s' % step_suffix, | 246 name='git checkout%s' % step_suffix, |
242 can_fail_build=can_fail_build) | 247 can_fail_build=can_fail_build) |
243 | 248 |
244 else: | 249 else: |
245 self('checkout', '-f', checkout_ref, | 250 self('checkout', '-f', checkout_ref, |
246 cwd=dir_path, | 251 cwd=dir_path, |
247 name='git checkout%s' % step_suffix, | 252 name='git checkout%s' % step_suffix, |
248 can_fail_build=can_fail_build) | 253 can_fail_build=can_fail_build) |
249 | 254 |
250 if set_got_revision: | 255 rev_parse_step = self('rev-parse', 'HEAD', |
251 rev_parse_step = self('rev-parse', 'HEAD', | 256 cwd=dir_path, |
252 cwd=dir_path, | 257 name='read revision', |
253 name='set got_revision', | 258 stdout=self.m.raw_io.output(), |
254 stdout=self.m.raw_io.output(), | 259 can_fail_build=False, |
255 can_fail_build=False) | 260 step_test_data=lambda: |
| 261 self.m.raw_io.test_api.stream_output('deadbeef')) |
256 | 262 |
257 if rev_parse_step.presentation.status == 'SUCCESS': | 263 if rev_parse_step.presentation.status == 'SUCCESS': |
258 sha = rev_parse_step.stdout.strip() | 264 sha = rev_parse_step.stdout.strip() |
| 265 retVal = sha |
| 266 rev_parse_step.presentation.step_text = "<br/>checked out %r<br/>" % sha |
| 267 if set_got_revision: |
259 rev_parse_step.presentation.properties['got_revision'] = sha | 268 rev_parse_step.presentation.properties['got_revision'] = sha |
260 | 269 |
261 clean_args = list(itertools.chain( | 270 clean_args = list(itertools.chain( |
262 *[('-e', path) for path in keep_paths or []])) | 271 *[('-e', path) for path in keep_paths or []])) |
263 | 272 |
264 self('clean', '-f', '-d', '-x', *clean_args, | 273 self('clean', '-f', '-d', '-x', *clean_args, |
265 name='git clean%s' % step_suffix, | 274 name='git clean%s' % step_suffix, |
266 cwd=dir_path, | 275 cwd=dir_path, |
267 can_fail_build=can_fail_build) | 276 can_fail_build=can_fail_build) |
268 | 277 |
269 if submodules: | 278 if submodules: |
270 self('submodule', 'sync', | 279 self('submodule', 'sync', |
271 name='submodule sync%s' % step_suffix, | 280 name='submodule sync%s' % step_suffix, |
272 cwd=dir_path, | 281 cwd=dir_path, |
273 can_fail_build=can_fail_build) | 282 can_fail_build=can_fail_build) |
274 submodule_update = ['submodule', 'update', '--init'] | 283 submodule_update = ['submodule', 'update', '--init'] |
275 if submodule_update_recursive: | 284 if submodule_update_recursive: |
276 submodule_update.append('--recursive') | 285 submodule_update.append('--recursive') |
277 if submodule_update_force: | 286 if submodule_update_force: |
278 submodule_update.append('--force') | 287 submodule_update.append('--force') |
279 self(*submodule_update, | 288 self(*submodule_update, |
280 name='submodule update%s' % step_suffix, | 289 name='submodule update%s' % step_suffix, |
281 cwd=dir_path, | 290 cwd=dir_path, |
282 can_fail_build=can_fail_build) | 291 can_fail_build=can_fail_build) |
283 | 292 |
| 293 return retVal |
| 294 |
284 def get_timestamp(self, commit='HEAD', test_data=None, **kwargs): | 295 def get_timestamp(self, commit='HEAD', test_data=None, **kwargs): |
285 """Find and return the timestamp of the given commit.""" | 296 """Find and return the timestamp of the given commit.""" |
286 step_test_data = None | 297 step_test_data = None |
287 if test_data is not None: | 298 if test_data is not None: |
288 step_test_data = lambda: self.m.raw_io.test_api.stream_output(test_data) | 299 step_test_data = lambda: self.m.raw_io.test_api.stream_output(test_data) |
289 return self('show', commit, '--format=%at', '-s', | 300 return self('show', commit, '--format=%at', '-s', |
290 stdout=self.m.raw_io.output(), | 301 stdout=self.m.raw_io.output(), |
291 step_test_data=step_test_data).stdout.rstrip() | 302 step_test_data=step_test_data).stdout.rstrip() |
292 | 303 |
293 def rebase(self, name_prefix, branch, dir_path, remote_name=None, | 304 def rebase(self, name_prefix, branch, dir_path, remote_name=None, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
340 | 351 |
341 Args: | 352 Args: |
342 bundle_path (Path): The path of the output bundle. | 353 bundle_path (Path): The path of the output bundle. |
343 refs (list): The list of refs to include in the bundle. If None, all | 354 refs (list): The list of refs to include in the bundle. If None, all |
344 refs in the Git checkout will be bundled. | 355 refs in the Git checkout will be bundled. |
345 kwargs: Forwarded to '__call__'. | 356 kwargs: Forwarded to '__call__'. |
346 """ | 357 """ |
347 if not rev_list_args: | 358 if not rev_list_args: |
348 rev_list_args = ['--all'] | 359 rev_list_args = ['--all'] |
349 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) | 360 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) |
OLD | NEW |