checkout: Add submodule timeout property

Add timeouts to 'git submodule update'. It usually takes no more than a
minute or two for most projects, but some projects will take much
longer. This lets it be configured per-builder.

Change-Id: I1aee9e16f114f279e69229cda70f3e37c67da7d5
Bug: 484, b/215647193
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/80861
Reviewed-by: Ted Pudlik <tpudlik@google.com>
Commit-Queue: Rob Mohr <mohrr@google.com>
diff --git a/recipe_modules/checkout/api.py b/recipe_modules/checkout/api.py
index e467a8c..c757693 100644
--- a/recipe_modules/checkout/api.py
+++ b/recipe_modules/checkout/api.py
@@ -165,6 +165,7 @@
         self._repo_init_timeout_sec = props.repo_init_timeout_sec or 20
         self._repo_sync_timeout_sec = props.repo_sync_timeout_sec or 120
         self._number_of_attempts = props.number_of_attempts or 3
+        self._submodule_timeout_sec = props.submodule_timeout_sec or 10 * 60.0
         self._submodule_data = {}
         self._equivalent_remotes = {}
         self._force_no_rebase = props.force_no_rebase
@@ -716,8 +717,13 @@
 
         with self.m.context(infra_steps=True):
             self.m.git.checkout(
-                remote, path=root, ref=branch, recursive=True, submodules=True
+                remote, path=root, ref=branch, recursive=True, submodules=False
             )
+            with self.m.step.nest('submodule'), self.m.context(cwd=root):
+                self.m.git.sync_submodule()
+                self.m.git.update_submodule(
+                    recursive=True, timeout=self._submodule_timeout_sec,
+                )
 
         with self.m.context(cwd=root):
             got_revision = None
diff --git a/recipe_modules/checkout/properties.proto b/recipe_modules/checkout/properties.proto
index 3122f18..79df27d 100644
--- a/recipe_modules/checkout/properties.proto
+++ b/recipe_modules/checkout/properties.proto
@@ -74,4 +74,8 @@
   // of any superprojects or manifests containing the CL's repo as a submodule
   // or project. (Note: branch matching is not yet implemented for submodules.)
   bool match_branch = 10;
+
+  // Timeout for 'git submodule update --init --recursive'. Default is
+  // 10 minutes.
+  int32 submodule_timeout_sec = 11;
 }