blob: 270a4186444029f6092d6369e86e24751706403e [file] [log] [blame]
# Copyright 2019 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
"""Calls to checkout code.
Usage:
api.checkout(remote='https://pigweed.googlesource.com/pigweed/pigweed')
"""
from recipe_engine import recipe_api
class CheckoutApi(recipe_api.RecipeApi):
"""Calls to checkout code."""
def __init__(self, *args, **kwargs):
super(CheckoutApi, self).__init__(*args, **kwargs)
self._root = None
def __call__(self, remote):
"""Checkout code from git.
Grabs data from buildbucket. If drawing a blank, uses remote. Returns
path to checkout.
Args:
remote (str): URL of git repository
"""
self._root = self.m.path['start_dir'].join('checkout')
with self.m.step.nest('checkout'):
with self.m.context(infra_steps=True):
bb_input = self.m.buildbucket.build.input
if bb_input.gerrit_changes:
self.m.git.checkout_cl(bb_input.gerrit_changes[0], path=self._root)
elif bb_input.gitiles_commit.project:
self.m.git.checkout_commit(bb_input.gitiles_commit, path=self._root)
else: # pragma: no cover
raise api.step.InfraFailure('no commit or CL specified')
with self.m.context(cwd=self._root):
self.m.step('git log',
['git', '--no-pager', 'log', '--oneline', 'HEAD~10..'])
@property
def root(self):
return self._root