diff --git a/recipe_modules/git/api.py b/recipe_modules/git/api.py
index 3832fc377..e8003dc66 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 = "
checked out %r
" % 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
diff --git a/recipe_modules/git/example.expected/basic.json b/recipe_modules/git/example.expected/basic.json
index 06d6fe8d3..b332cdf60 100644
--- a/recipe_modules/git/example.expected/basic.json
+++ b/recipe_modules/git/example.expected/basic.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/basic_branch.json b/recipe_modules/git/example.expected/basic_branch.json
index 7ca833610..56fb11cdd 100644
--- a/recipe_modules/git/example.expected/basic_branch.json
+++ b/recipe_modules/git/example.expected/basic_branch.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/basic_file_name.json b/recipe_modules/git/example.expected/basic_file_name.json
index acf4c9c17..b5b08456c 100644
--- a/recipe_modules/git/example.expected/basic_file_name.json
+++ b/recipe_modules/git/example.expected/basic_file_name.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/basic_hash.json b/recipe_modules/git/example.expected/basic_hash.json
index c2f801b44..fe9468f50 100644
--- a/recipe_modules/git/example.expected/basic_hash.json
+++ b/recipe_modules/git/example.expected/basic_hash.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/basic_ref.json b/recipe_modules/git/example.expected/basic_ref.json
index 67b857696..eb8aadfe0 100644
--- a/recipe_modules/git/example.expected/basic_ref.json
+++ b/recipe_modules/git/example.expected/basic_ref.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/basic_submodule_update_force.json b/recipe_modules/git/example.expected/basic_submodule_update_force.json
index b4141be19..f19168b55 100644
--- a/recipe_modules/git/example.expected/basic_submodule_update_force.json
+++ b/recipe_modules/git/example.expected/basic_submodule_update_force.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/can_fail_build.json b/recipe_modules/git/example.expected/can_fail_build.json
index 5fafd562f..30d92d2db 100644
--- a/recipe_modules/git/example.expected/can_fail_build.json
+++ b/recipe_modules/git/example.expected/can_fail_build.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/cannot_fail_build.json b/recipe_modules/git/example.expected/cannot_fail_build.json
index 03cabd23f..4b65540d1 100644
--- a/recipe_modules/git/example.expected/cannot_fail_build.json
+++ b/recipe_modules/git/example.expected/cannot_fail_build.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/cat-file_test.json b/recipe_modules/git/example.expected/cat-file_test.json
index 116c93906..513457abb 100644
--- a/recipe_modules/git/example.expected/cat-file_test.json
+++ b/recipe_modules/git/example.expected/cat-file_test.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/count-objects_delta.json b/recipe_modules/git/example.expected/count-objects_delta.json
index 388083aa8..b2ca9cb4c 100644
--- a/recipe_modules/git/example.expected/count-objects_delta.json
+++ b/recipe_modules/git/example.expected/count-objects_delta.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/count-objects_failed.json b/recipe_modules/git/example.expected/count-objects_failed.json
index 7e91538bf..2087e3de5 100644
--- a/recipe_modules/git/example.expected/count-objects_failed.json
+++ b/recipe_modules/git/example.expected/count-objects_failed.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/count-objects_with_bad_output.json b/recipe_modules/git/example.expected/count-objects_with_bad_output.json
index 95f94c51f..26cc6c13d 100644
--- a/recipe_modules/git/example.expected/count-objects_with_bad_output.json
+++ b/recipe_modules/git/example.expected/count-objects_with_bad_output.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/count-objects_with_bad_output_fails_build.json b/recipe_modules/git/example.expected/count-objects_with_bad_output_fails_build.json
index 8f6afbcb8..d044d15e5 100644
--- a/recipe_modules/git/example.expected/count-objects_with_bad_output_fails_build.json
+++ b/recipe_modules/git/example.expected/count-objects_with_bad_output_fails_build.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/curl_trace_file.json b/recipe_modules/git/example.expected/curl_trace_file.json
index 4c31389e7..a0b28fa35 100644
--- a/recipe_modules/git/example.expected/curl_trace_file.json
+++ b/recipe_modules/git/example.expected/curl_trace_file.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/platform_win.json b/recipe_modules/git/example.expected/platform_win.json
index 6466e56e0..040a832b0 100644
--- a/recipe_modules/git/example.expected/platform_win.json
+++ b/recipe_modules/git/example.expected/platform_win.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"[DEPOT_TOOLS]\\git.bat",
diff --git a/recipe_modules/git/example.expected/rebase_failed.json b/recipe_modules/git/example.expected/rebase_failed.json
index 32724530b..39666c74d 100644
--- a/recipe_modules/git/example.expected/rebase_failed.json
+++ b/recipe_modules/git/example.expected/rebase_failed.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/remote_not_origin.json b/recipe_modules/git/example.expected/remote_not_origin.json
index 3f3bc8bfe..f1b6f2eb6 100644
--- a/recipe_modules/git/example.expected/remote_not_origin.json
+++ b/recipe_modules/git/example.expected/remote_not_origin.json
@@ -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@
checked out 'deadbeef'
@@@"
+ ]
+ },
{
"cmd": [
"git",
diff --git a/recipe_modules/git/example.expected/set_got_revision.json b/recipe_modules/git/example.expected/set_got_revision.json
index 37349f2a9..f0eb36a3e 100644
--- a/recipe_modules/git/example.expected/set_got_revision.json
+++ b/recipe_modules/git/example.expected/set_got_revision.json
@@ -41,9 +41,10 @@
"HEAD"
],
"cwd": "[SLAVE_BUILD]/src",
- "name": "set got_revision",
+ "name": "read revision",
"stdout": "/path/to/tmp/",
"~followup_annotations": [
+ "@@@STEP_TEXT@
checked out 'deadbeef'
@@@",
"@@@SET_BUILD_PROPERTY@got_revision@\"deadbeef\"@@@"
]
},
diff --git a/recipe_modules/git/example.py b/recipe_modules/git/example.py
index dc9fe0a87..066785a2a 100644
--- a/recipe_modules/git/example.py
+++ b/recipe_modules/git/example.py
@@ -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 (