Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(387)

Unified Diff: recipe_modules/git/api.py

Issue 1693993002: Make git.checkout return the commit hash. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | recipe_modules/git/example.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: recipe_modules/git/api.py
diff --git a/recipe_modules/git/api.py b/recipe_modules/git/api.py
index 3832fc3779e7f52e4077969b310064fe13844c09..e8003dc666c9e7c2e8e554ec544bd50cc3035064 100644
--- a/recipe_modules/git/api.py
+++ b/recipe_modules/git/api.py
@@ -140,7 +140,12 @@ class GitApi(recipe_api.RecipeApi):
file_name (str): optional path to a single file to checkout.
submodule_update_recursive (bool): if True, updates submodules
recursively.
+
+ Returns: If the checkout was successful, this returns the commit hash of
+ the checked-out-repo. Otherwise this returns None.
"""
+ retVal = None
+
# TODO(robertocn): Break this function and refactor calls to it.
# The problem is that there are way too many unrealated use cases for
# it, and the function's signature is getting unwieldy and its body
@@ -247,15 +252,19 @@ class GitApi(recipe_api.RecipeApi):
name='git checkout%s' % step_suffix,
can_fail_build=can_fail_build)
- if set_got_revision:
- rev_parse_step = self('rev-parse', 'HEAD',
- cwd=dir_path,
- name='set got_revision',
- stdout=self.m.raw_io.output(),
- can_fail_build=False)
-
- if rev_parse_step.presentation.status == 'SUCCESS':
- sha = rev_parse_step.stdout.strip()
+ rev_parse_step = self('rev-parse', 'HEAD',
+ cwd=dir_path,
+ name='read revision',
+ stdout=self.m.raw_io.output(),
+ can_fail_build=False,
+ step_test_data=lambda:
+ self.m.raw_io.test_api.stream_output('deadbeef'))
+
+ if rev_parse_step.presentation.status == 'SUCCESS':
+ sha = rev_parse_step.stdout.strip()
+ retVal = sha
+ rev_parse_step.presentation.step_text = "<br/>checked out %r<br/>" % sha
+ if set_got_revision:
rev_parse_step.presentation.properties['got_revision'] = sha
clean_args = list(itertools.chain(
@@ -281,6 +290,8 @@ class GitApi(recipe_api.RecipeApi):
cwd=dir_path,
can_fail_build=can_fail_build)
+ return retVal
+
def get_timestamp(self, commit='HEAD', test_data=None, **kwargs):
"""Find and return the timestamp of the given commit."""
step_test_data = None
« no previous file with comments | « no previous file | recipe_modules/git/example.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698