Fix dart_3p rolling API.

It was assuming the gerrit_host is always fuchsia-review which may not
be always true. Additionally fixes a problem with duplicated change ids.

Bug: 36488
Bug: 36497
Change-Id: I796089249cac9af7c4f74ce170d316ef225b81f0
diff --git a/recipe_modules/dart_util/api.py b/recipe_modules/dart_util/api.py
index c1270d8..dcdc74a 100644
--- a/recipe_modules/dart_util/api.py
+++ b/recipe_modules/dart_util/api.py
@@ -45,7 +45,7 @@
     Returns:
       A string with third_party/dart-pkg/pub latest commit hash.
     """
-    commit_msg = '[roll] Update third-party dart packages'
+    commit_msg = '[roll] Update third-party dart packages\n'
     packages_root = checkout_root.join('third_party', 'dart-pkg', 'pub')
     with self.m.context(cwd=packages_root):
       # Make sure third_party/dart-pkg is at origin/master before running the
@@ -55,11 +55,19 @@
       self.m.git('checkout', 'origin/master')
       current_hash = self.m.git.get_hash()
       self.run_update_3p_packages(checkout_root)
+      # We need to temporarily set gerrit host to fuchsia-review. Gerrit host is
+      # set at the beginning of the recipe execution using the gerrit_host
+      # property passed to the recipe and it may different from fuchsia-review
+      # if the recipe is interacting with several gerrit hosts.
+      old_gerrit_host = self.m.gerrit.host
+      self.m.gerrit.host = 'https://fuchsia-review.googlesource.com'
       rolled = self.m.auto_roller.attempt_roll(
-          gerrit_project='third_party/dart-pkg/pub',
+          gerrit_project='third_party/dart-pkg',
           repo_dir=packages_root,
           commit_message=commit_msg,
+          commit_untracked=True,
           dry_run=dry_run)
+      self.m.gerrit.host = old_gerrit_host
       current_hash = self.m.git.get_hash()
     self.m.step.active_result.presentation.logs['revision'] = [current_hash]
     return current_hash
diff --git a/recipe_modules/dart_util/examples/full.expected/default.json b/recipe_modules/dart_util/examples/full.expected/default.json
index 3198b7b..73b5980 100644
--- a/recipe_modules/dart_util/examples/full.expected/default.json
+++ b/recipe_modules/dart_util/examples/full.expected/default.json
@@ -334,7 +334,8 @@
       "ls-files",
       "--modified",
       "--deleted",
-      "--exclude-standard"
+      "--exclude-standard",
+      "--others"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
     "name": "check for no-op commit",
@@ -346,6 +347,16 @@
   {
     "cmd": [
       "git",
+      "add",
+      "--all",
+      "--intent-to-add"
+    ],
+    "cwd": "[START_DIR]/third_party/dart-pkg/pub",
+    "name": "git add"
+  },
+  {
+    "cmd": [
+      "git",
       "diff"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -365,7 +376,7 @@
       "git",
       "commit",
       "-m",
-      "[roll] Update third-party dart packages\nChange-Id: Iabc123\n",
+      "[roll] Update third-party dart packages\n\nChange-Id: Iabc123\n",
       "-a"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -424,7 +435,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\", \"input\": {\"labels\": {\"Commit-Queue\": 1}}, \"revision_id\": \"current\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\", \"input\": {\"labels\": {\"Commit-Queue\": 1}}, \"revision_id\": \"current\"}",
       "-output",
       "/path/to/tmp/json"
     ],
@@ -447,7 +458,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\"}",
       "-output",
       "/path/to/tmp/json"
     ],
@@ -472,7 +483,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\"}",
       "-output",
       "/path/to/tmp/json"
     ],
@@ -540,7 +551,8 @@
       "ls-files",
       "--modified",
       "--deleted",
-      "--exclude-standard"
+      "--exclude-standard",
+      "--others"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
     "name": "check for no-op commit (2)",
@@ -552,6 +564,16 @@
   {
     "cmd": [
       "git",
+      "add",
+      "--all",
+      "--intent-to-add"
+    ],
+    "cwd": "[START_DIR]/third_party/dart-pkg/pub",
+    "name": "git add (2)"
+  },
+  {
+    "cmd": [
+      "git",
       "diff"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -571,7 +593,7 @@
       "git",
       "commit",
       "-m",
-      "[roll] Update third-party dart packages\nChange-Id: Iabc123\n",
+      "[roll] Update third-party dart packages\n\nChange-Id: Iabc123\n",
       "-a"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -597,7 +619,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\", \"input\": {\"labels\": {\"Code-Review\": 2, \"Commit-Queue\": 2}}, \"revision_id\": \"current\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\", \"input\": {\"labels\": {\"Code-Review\": 2, \"Commit-Queue\": 2}}, \"revision_id\": \"current\"}",
       "-output",
       "/path/to/tmp/json"
     ],
@@ -620,7 +642,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\"}",
       "-output",
       "/path/to/tmp/json"
     ],
diff --git a/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree.json b/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree.json
index 5630c13..e1ce641 100644
--- a/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree.json
+++ b/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree.json
@@ -774,7 +774,8 @@
       "ls-files",
       "--modified",
       "--deleted",
-      "--exclude-standard"
+      "--exclude-standard",
+      "--others"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
     "name": "third-party dart packages.check for no-op commit",
@@ -787,6 +788,19 @@
   {
     "cmd": [
       "git",
+      "add",
+      "--all",
+      "--intent-to-add"
+    ],
+    "cwd": "[START_DIR]/third_party/dart-pkg/pub",
+    "name": "third-party dart packages.git add",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "diff"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -812,7 +826,7 @@
       "git",
       "commit",
       "-m",
-      "[roll] Update third-party dart packages\nChange-Id: Iabc123\n",
+      "[roll] Update third-party dart packages\n\nChange-Id: Iabc123\n",
       "-a"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -878,7 +892,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\", \"input\": {\"labels\": {\"Code-Review\": 2, \"Commit-Queue\": 2}}, \"revision_id\": \"current\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\", \"input\": {\"labels\": {\"Code-Review\": 2, \"Commit-Queue\": 2}}, \"revision_id\": \"current\"}",
       "-output",
       "/path/to/tmp/json"
     ],
@@ -905,7 +919,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\"}",
       "-output",
       "/path/to/tmp/json"
     ],
diff --git a/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree_dry_run.json b/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree_dry_run.json
index 2d26310..6245c28 100644
--- a/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree_dry_run.json
+++ b/recipes/flutter_with_dependents_roller.expected/orchestrator_dep_version_different_from_tree_dry_run.json
@@ -774,7 +774,8 @@
       "ls-files",
       "--modified",
       "--deleted",
-      "--exclude-standard"
+      "--exclude-standard",
+      "--others"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
     "name": "third-party dart packages.check for no-op commit",
@@ -787,6 +788,19 @@
   {
     "cmd": [
       "git",
+      "add",
+      "--all",
+      "--intent-to-add"
+    ],
+    "cwd": "[START_DIR]/third_party/dart-pkg/pub",
+    "name": "third-party dart packages.git add",
+    "~followup_annotations": [
+      "@@@STEP_NEST_LEVEL@1@@@"
+    ]
+  },
+  {
+    "cmd": [
+      "git",
       "diff"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -812,7 +826,7 @@
       "git",
       "commit",
       "-m",
-      "[roll] Update third-party dart packages\nChange-Id: Iabc123\n",
+      "[roll] Update third-party dart packages\n\nChange-Id: Iabc123\n",
       "-a"
     ],
     "cwd": "[START_DIR]/third_party/dart-pkg/pub",
@@ -878,7 +892,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\", \"input\": {\"labels\": {\"Code-Review\": 2, \"Commit-Queue\": 2}}, \"revision_id\": \"current\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\", \"input\": {\"labels\": {\"Code-Review\": 2, \"Commit-Queue\": 2}}, \"revision_id\": \"current\"}",
       "-output",
       "/path/to/tmp/json"
     ],
@@ -905,7 +919,7 @@
       "-host",
       "https://fuchsia-review.googlesource.com",
       "-input",
-      "{\"change_id\": \"third_party/dart-pkg/pub~master~Iabc123\"}",
+      "{\"change_id\": \"third_party/dart-pkg~master~Iabc123\"}",
       "-output",
       "/path/to/tmp/json"
     ],