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): |
11 _GIT_HASH_RE = re.compile('[0-9a-f]{40}', re.IGNORECASE) | 11 _GIT_HASH_RE = re.compile('[0-9a-f]{40}', re.IGNORECASE) |
12 | 12 |
13 def __call__(self, *args, **kwargs): | 13 def __call__(self, *args, **kwargs): |
14 """Return a git command step.""" | 14 """Return a git command step.""" |
15 name = kwargs.pop('name', 'git '+args[0]) | 15 name = kwargs.pop('name', 'git '+args[0]) |
16 infra_step = kwargs.pop('infra_step', True) | 16 infra_step = kwargs.pop('infra_step', True) |
17 if 'cwd' not in kwargs: | 17 if 'cwd' not in kwargs: |
18 kwargs.setdefault('cwd', self.m.path['checkout']) | 18 kwargs.setdefault('cwd', self.m.path['checkout']) |
19 git_cmd = ['git'] | 19 git_cmd = ['git'] |
20 if self.m.platform.is_win: | 20 if self.m.platform.is_win: |
21 git_cmd = [self.m.path['depot_tools'].join('git.bat')] | 21 git_cmd = [self.package_resource('git.bat')] |
22 options = kwargs.pop('git_config_options', {}) | 22 options = kwargs.pop('git_config_options', {}) |
23 for k, v in sorted(options.iteritems()): | 23 for k, v in sorted(options.iteritems()): |
24 git_cmd.extend(['-c', '%s=%s' % (k, v)]) | 24 git_cmd.extend(['-c', '%s=%s' % (k, v)]) |
25 can_fail_build = kwargs.pop('can_fail_build', True) | 25 can_fail_build = kwargs.pop('can_fail_build', True) |
26 try: | 26 try: |
27 return self.m.step(name, git_cmd + list(args), infra_step=infra_step, | 27 return self.m.step(name, git_cmd + list(args), infra_step=infra_step, |
28 **kwargs) | 28 **kwargs) |
29 except self.m.step.StepFailure as f: | 29 except self.m.step.StepFailure as f: |
30 if can_fail_build: | 30 if can_fail_build: |
31 raise | 31 raise |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 self.m.path['checkout'] = dir_path | 165 self.m.path['checkout'] = dir_path |
166 | 166 |
167 git_setup_args = ['--path', dir_path, '--url', url] | 167 git_setup_args = ['--path', dir_path, '--url', url] |
168 | 168 |
169 if remote_name: | 169 if remote_name: |
170 git_setup_args += ['--remote', remote_name] | 170 git_setup_args += ['--remote', remote_name] |
171 else: | 171 else: |
172 remote_name = 'origin' | 172 remote_name = 'origin' |
173 | 173 |
174 if self.m.platform.is_win: | 174 if self.m.platform.is_win: |
175 git_setup_args += ['--git_cmd_path', | 175 git_setup_args += ['--git_cmd_path', self.package_resource('git.bat')] |
176 self.m.path['depot_tools'].join('git.bat')] | |
177 | 176 |
178 step_suffix = '' if step_suffix is None else ' (%s)' % step_suffix | 177 step_suffix = '' if step_suffix is None else ' (%s)' % step_suffix |
179 self.m.python( | 178 self.m.python( |
180 'git setup%s' % step_suffix, | 179 'git setup%s' % step_suffix, |
181 self.resource('git_setup.py'), | 180 self.resource('git_setup.py'), |
182 git_setup_args) | 181 git_setup_args) |
183 | 182 |
184 # There are five kinds of refs we can be handed: | 183 # There are five kinds of refs we can be handed: |
185 # 0) None. In this case, we default to properties['branch']. | 184 # 0) None. In this case, we default to properties['branch']. |
186 # 1) A 40-character SHA1 hash. | 185 # 1) A 40-character SHA1 hash. |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 | 350 |
352 Args: | 351 Args: |
353 bundle_path (Path): The path of the output bundle. | 352 bundle_path (Path): The path of the output bundle. |
354 refs (list): The list of refs to include in the bundle. If None, all | 353 refs (list): The list of refs to include in the bundle. If None, all |
355 refs in the Git checkout will be bundled. | 354 refs in the Git checkout will be bundled. |
356 kwargs: Forwarded to '__call__'. | 355 kwargs: Forwarded to '__call__'. |
357 """ | 356 """ |
358 if not rev_list_args: | 357 if not rev_list_args: |
359 rev_list_args = ['--all'] | 358 rev_list_args = ['--all'] |
360 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) | 359 self('bundle', 'create', bundle_path, *rev_list_args, **kwargs) |
OLD | NEW |