Commit 846218da authored by iannucci@chromium.org's avatar iannucci@chromium.org

Make git.checkout return the commit hash.

R=dnj@chromium.org, hinoka@chromium.org, luqui@chromium.org, martiniss@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1693993002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@298774 0039d316-1c4b-4281-b951-d872f2087c98
parent 85ef669c
......@@ -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
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -36,6 +36,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -33,6 +33,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -107,6 +107,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -38,6 +38,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -36,6 +36,19 @@
"cwd": "[SLAVE_BUILD]\\src",
"name": "git checkout"
},
{
"cmd": [
"[DEPOT_TOOLS]\\git.bat",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]\\src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"[DEPOT_TOOLS]\\git.bat",
......
......@@ -34,6 +34,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -36,6 +36,19 @@
"cwd": "[SLAVE_BUILD]/src",
"name": "git checkout"
},
{
"cmd": [
"git",
"rev-parse",
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@"
]
},
{
"cmd": [
"git",
......
......@@ -41,9 +41,10 @@
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
"name": "set got_revision",
"name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
"@@@STEP_TEXT@<br/>checked out 'deadbeef'<br/>@@@",
"@@@SET_BUILD_PROPERTY@got_revision@\"deadbeef\"@@@"
]
},
......
......@@ -26,7 +26,7 @@ def RunSteps(api):
True)
# You can use api.git.checkout to perform all the steps of a safe checkout.
api.git.checkout(
retVal = api.git.checkout(
url,
ref=api.properties.get('revision'),
recursive=True,
......@@ -38,6 +38,9 @@ def RunSteps(api):
file_name=api.properties.get('checkout_file_name'),
submodule_update_recursive=submodule_update_recursive)
assert retVal == "deadbeef", (
"expected retVal to be %r but was %r" % ("deadbeef", retVal))
# count_objects shows number and size of objects in .git dir.
api.git.count_objects(
name='count-objects',
......@@ -106,10 +109,8 @@ def GenTests(api):
)
yield (
api.test('set_got_revision') +
api.properties(set_got_revision=True) +
api.step_data('set got_revision',
stdout=api.raw_io.output('deadbeef'))
api.test('set_got_revision') +
api.properties(set_got_revision=True)
)
yield (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment