Update to override sha when checking out multiple repoistories with cocoon.
When we currently perform a checkout of cocoon and flutter we get the cocoon sha from the build. We checkout that version of cocoon and then when we go to checkout flutter we end up using that sha so then the flutter checkout fails since that commit in cocoon is not in the flutter repo. This just allows us to override that and use the original ref which for the coming change is just the tot master branch.
Bug: https://github.com/flutter/flutter/issues/119012
Change-Id: Ie422c9c8e22ecbf96e73563dcfa61a3cbf4fb6f3
Reviewed-on: https://flutter-review.googlesource.com/c/recipes/+/38133
Reviewed-by: Yusuf Mohsinally <mohsinally@google.com>
Commit-Queue: Ricardo Amador <ricardoamador@google.com>
diff --git a/recipe_modules/repo_util/api.py b/recipe_modules/repo_util/api.py
index 60a66d6..93fdf83 100644
--- a/recipe_modules/repo_util/api.py
+++ b/recipe_modules/repo_util/api.py
@@ -209,7 +209,7 @@
max_attempts=4
)
- def checkout(self, name, checkout_path, url=None, ref=None):
+ def checkout(self, name, checkout_path, url=None, ref=None, override_sha=False):
"""Checks out a repo and returns sha1 of checked out revision.
The supported repository names and their urls are defined in the global
@@ -220,6 +220,7 @@
checkout_path (Path): directory to clone into.
url (str): optional url overwrite of the remote repo.
ref (str): optional ref overwrite to fetch and check out.
+ override_sha (bool): flag to override the commit sha and used the passed in ref.
"""
if name not in REPOS:
raise ValueError('Unsupported repo: %s' % name)
@@ -230,10 +231,15 @@
# if this a release build, self.m.buildbucket.gitiles_commit.id should have more priority than
# ref since it is more specific, and we don't want to default to refs/heads/<REPO_BRANCHES[name]>
if ref in ['refs/heads/beta', 'refs/heads/stable']:
- git_ref = (
- self.m.buildbucket.gitiles_commit.id or
- self.m.buildbucket.gitiles_commit.ref or ref
- )
+ # When we currently perform a checkout of cocoon and flutter we get the cocoon sha from the
+ # build. We checkout that version of cocoon and then when we go to checkout flutter we end
+ # up using that sha so then the flutter checkout fails since that commit in cocoon is not in
+ # the flutter repo. This just allows us to override that and use the original ref which for
+ # the coming change is just the tot master branch.
+ git_ref = ref if override_sha else (
+ self.m.buildbucket.gitiles_commit.id or
+ self.m.buildbucket.gitiles_commit.ref or ref
+ )
else:
git_ref = (
ref or self.m.buildbucket.gitiles_commit.id or
diff --git a/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json b/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json
index cfedb07..c312914 100644
--- a/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json
+++ b/recipe_modules/repo_util/examples/unsupported.expected/unsupported.json
@@ -9,7 +9,7 @@
"Traceback (most recent call last):",
" File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/examples/unsupported.py\", line 13, in RunSteps",
" api.repo_util.checkout('unsupported_repo', repo_dir)",
- " File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/api.py\", line 225, in checkout",
+ " File \"RECIPE_REPO[flutter]/recipe_modules/repo_util/api.py\", line 226, in checkout",
" raise ValueError('Unsupported repo: %s' % name)",
"ValueError('Unsupported repo: unsupported_repo')"
]