submodule_roll: Use Fuchsia module for getting rev

Use the Fuchsia git_roll_util module for getting the new revision. Also,
it looks like Pigweed was ignoring the buildbucket commit when deciding
on the new commit.

Bug: b/359925419
Change-Id: I2ef01aa8bb7630d0f4acb5f3b69f24f29ef1a1cf
Reviewed-on: https://pigweed-review.googlesource.com/c/infra/recipes/+/230791
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Reviewed-by: Danielle Kay <danikay@google.com>
Pigweed-Auto-Submit: Rob Mohr <mohrr@google.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
diff --git a/recipe_modules/submodule_roll/__init__.py b/recipe_modules/submodule_roll/__init__.py
index 2cfcef4..9e22558 100644
--- a/recipe_modules/submodule_roll/__init__.py
+++ b/recipe_modules/submodule_roll/__init__.py
@@ -18,6 +18,7 @@
 
 DEPS = [
     'fuchsia/git',
+    'fuchsia/git_roll_util',
     'pigweed/checkout',
     'pigweed/roll_util',
     'recipe_engine/context',
diff --git a/recipe_modules/submodule_roll/api.py b/recipe_modules/submodule_roll/api.py
index 6d87693..9c0da26 100644
--- a/recipe_modules/submodule_roll/api.py
+++ b/recipe_modules/submodule_roll/api.py
@@ -133,10 +133,16 @@
                     checkout.options.remote,
                 )
 
+                new_revision = self.m.git_roll_util.resolve_new_revision(
+                    submodule.remote,
+                    submodule.branch,
+                    checkout.remotes_equivalent,
+                )
+
                 change = self.update_pin(
                     checkout,
                     submodule.dir,
-                    submodule.branch,
+                    new_revision,
                 )
 
                 direction = self.m.roll_util.get_roll_direction(
diff --git a/recipe_modules/submodule_roll/tests/full.expected/missing.json b/recipe_modules/submodule_roll/tests/full.expected/missing.json
index 0d4a2ae..807f498 100644
--- a/recipe_modules/submodule_roll/tests/full.expected/missing.json
+++ b/recipe_modules/submodule_roll/tests/full.expected/missing.json
@@ -29,6 +29,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/a1",
+      "main"
+    ],
+    "name": "a1.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -62,7 +78,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/checkout/a1",
     "name": "a1.git fetch",
diff --git a/recipe_modules/submodule_roll/tests/full.expected/noop.json b/recipe_modules/submodule_roll/tests/full.expected/noop.json
index 50ac01d..006b9dd 100644
--- a/recipe_modules/submodule_roll/tests/full.expected/noop.json
+++ b/recipe_modules/submodule_roll/tests/full.expected/noop.json
@@ -33,6 +33,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/a1",
+      "main"
+    ],
+    "name": "a1.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -66,7 +82,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/checkout/a1",
     "name": "a1.git fetch",
@@ -168,6 +184,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/b2",
+      "branch"
+    ],
+    "name": "b2.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/branch@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -201,7 +233,7 @@
       "git",
       "fetch",
       "origin",
-      "branch"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/checkout/b2",
     "name": "b2.git fetch",
diff --git a/recipe_modules/submodule_roll/tests/full.expected/partial_noop.json b/recipe_modules/submodule_roll/tests/full.expected/partial_noop.json
index 2c6309c..556c735 100644
--- a/recipe_modules/submodule_roll/tests/full.expected/partial_noop.json
+++ b/recipe_modules/submodule_roll/tests/full.expected/partial_noop.json
@@ -29,6 +29,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/a1",
+      "main"
+    ],
+    "name": "a1.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -62,7 +78,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/checkout/a1",
     "name": "a1.git fetch",
@@ -364,6 +380,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/b2",
+      "main"
+    ],
+    "name": "b2.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -397,7 +429,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/checkout/b2",
     "name": "b2.git fetch",
diff --git a/recipe_modules/submodule_roll/tests/full.expected/success.json b/recipe_modules/submodule_roll/tests/full.expected/success.json
index 9173e46..74c224e 100644
--- a/recipe_modules/submodule_roll/tests/full.expected/success.json
+++ b/recipe_modules/submodule_roll/tests/full.expected/success.json
@@ -29,6 +29,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/a1",
+      "main"
+    ],
+    "name": "a1.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -62,7 +78,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/checkout/a1",
     "name": "a1.git fetch",
@@ -361,6 +377,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/b2",
+      "main"
+    ],
+    "name": "b2.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -394,7 +426,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/checkout/b2",
     "name": "b2.git fetch",
diff --git a/recipes/submodule_roller.expected/noop.json b/recipes/submodule_roller.expected/noop.json
index 0508a14..bfb00b0 100644
--- a/recipes/submodule_roller.expected/noop.json
+++ b/recipes/submodule_roller.expected/noop.json
@@ -613,6 +613,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/a1",
+      "main"
+    ],
+    "name": "a1.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -647,7 +663,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/co/a1",
     "name": "a1.git fetch",
@@ -749,6 +765,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/b2",
+      "branch"
+    ],
+    "name": "b2.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/branch@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -783,7 +815,7 @@
       "git",
       "fetch",
       "origin",
-      "branch"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/co/b2",
     "name": "b2.git fetch",
diff --git a/recipes/submodule_roller.expected/partial_noop.json b/recipes/submodule_roller.expected/partial_noop.json
index ad7788b..96f2aac 100644
--- a/recipes/submodule_roller.expected/partial_noop.json
+++ b/recipes/submodule_roller.expected/partial_noop.json
@@ -609,6 +609,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/a1",
+      "main"
+    ],
+    "name": "a1.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -643,7 +659,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/co/a1",
     "name": "a1.git fetch",
@@ -945,6 +961,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/b2",
+      "main"
+    ],
+    "name": "b2.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -979,7 +1011,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/co/b2",
     "name": "b2.git fetch",
diff --git a/recipes/submodule_roller.expected/success.json b/recipes/submodule_roller.expected/success.json
index a48bbb8..f46620a 100644
--- a/recipes/submodule_roller.expected/success.json
+++ b/recipes/submodule_roller.expected/success.json
@@ -609,6 +609,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/a1",
+      "main"
+    ],
+    "name": "a1.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -643,7 +659,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/co/a1",
     "name": "a1.git fetch",
@@ -942,6 +958,22 @@
   {
     "cmd": [
       "git",
+      "ls-remote",
+      "--heads",
+      "https://foo.googlesource.com/b2",
+      "main"
+    ],
+    "name": "b2.git ls-remote",
+    "timeout": 600.0,
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@",
+      "@@@STEP_LOG_LINE@stdout@h3ll0\trefs/heads/main@@@",
+      "@@@STEP_LOG_END@stdout@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "submodule",
       "update",
       "--init",
@@ -976,7 +1008,7 @@
       "git",
       "fetch",
       "origin",
-      "main"
+      "h3ll0"
     ],
     "cwd": "[START_DIR]/co/b2",
     "name": "b2.git fetch",