[checkout] Override gitiles_commit in buildbucket build input with
gitiles_commit from properties.

In some recipes like fuchsia/build.py, the gitiles_commit from the
buildbucket.build.input gets reused, so it should be the same as the
gitiles_commit used for the checkout.

Bug: 43619
Change-Id: I8a924a2f7d4af8d631f23ec4edf7f56ec492440b
diff --git a/recipe_modules/checkout/__init__.py b/recipe_modules/checkout/__init__.py
index b3606c2..a2143be 100644
--- a/recipe_modules/checkout/__init__.py
+++ b/recipe_modules/checkout/__init__.py
@@ -24,7 +24,7 @@
 PROPERTIES = {
     'checkout.buildset':
         Property(
-            help='gitiles commit to checkout',
+            help='gitiles commit to checkout. This will replace the gitiles_commit in buildbucket.build.input.',
             param_name='buildset',
             kind=str,
             default=None,
diff --git a/recipe_modules/checkout/api.py b/recipe_modules/checkout/api.py
index c75d086..2aa64e9 100644
--- a/recipe_modules/checkout/api.py
+++ b/recipe_modules/checkout/api.py
@@ -195,10 +195,18 @@
   def from_spec(self, checkout_spec):
     """Initialize a Fuchsia checkout according to a checkout spec.
 
+    If a gitiles_commit was provided through the buildset property, this will
+    set the buildbucket.build.input's gitiles_commit to the gitiles_commit from
+    the property.
+
     Args:
       checkout_spec: infra.fuchsia.Fuchsia.Checkout protocol buffer message.
     """
     build = self.m.buildbucket.build
+    if self._gitiles_commit:
+      # Override build input gitiles_commit with gitiles_commit from
+      # properties.
+      build.input.gitiles_commit.CopyFrom(self._gitiles_commit)
     checkout_root = self.m.path['start_dir'].join('fuchsia')
     if checkout_spec.use_snapshot:
       if self.m.buildbucket_util.is_tryjob:
@@ -206,12 +214,8 @@
         checkout = self.from_patchset_snapshot(
             path=checkout_root, gerrit_change=build.input.gerrit_changes[0])
       else:
-        commit = build.input.gitiles_commit
-        if self._gitiles_commit:
-          # Use gitiles_commit from properties instead of build input.
-          commit = self._gitiles_commit
         checkout = self.from_commit_snapshot(
-            path=checkout_root, gitiles_commit=commit)
+            path=checkout_root, gitiles_commit=build.input.gitiles_commit)
     else:
       assert checkout_spec.manifest
       assert checkout_spec.remote