superproject: Don't update the commit ids of projects if remote is different.

1) Skip setting the revision id (commit id) for the projects whose
   remote doesn't match superproject's remote.
2) exp-superproject/superproject_override.xml includes local_manfiest's
   projects. When we load this XML, don't reload projects from local.xml
   (otherwise we will get duplicate projects errors).

Tested the code with the following commands.

$ ./run_tests -v

+ Test with local.xml
  $ repo_dev init -u sso://android.git.corp.google.com/platform/manifest -b master --use-superproject --partial-clone --clone-filter=blob:limit=10M && mkdir -p .repo/local_manifests && (gcertstatus -quiet=true || gcert) && ln -s /google/src/head/depot/google3/wireless/android/build_tools/aosp/manifests/mirror-aosp-master-with-vendor/local.xml  .repo/local_manifests/local.xml

  $ repo_dev sync -c -j8

+ Test without local.xml
  $ repo_dev init -u sso://android.git.corp.google.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M --repo-rev=main --use-superproject
  $ repo_dev sync -c -j8

Bug: [google internal] b/186395810
Change-Id: I4e9d4ac2d94a9fc0cef0ccd787b6310758009e86
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/304882
Tested-by: Raman Tenneti <rtenneti@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py
index 9550949..5c1455f 100644
--- a/tests/test_git_superproject.py
+++ b/tests/test_git_superproject.py
@@ -141,12 +141,12 @@
       manifest_xml = fp.read()
     self.assertEqual(
         manifest_xml,
-        '<?xml version="1.0" ?><manifest>' +
-        '<remote name="default-remote" fetch="http://localhost"/>' +
-        '<default remote="default-remote" revision="refs/heads/main"/>' +
-        '<project name="platform/art" path="art" revision="ABCDEF" ' +
-        'groups="notdefault,platform-' + self.platform + '"/>' +
-        '<superproject name="superproject"/>' +
+        '<?xml version="1.0" ?><manifest>'
+        '<remote name="default-remote" fetch="http://localhost"/>'
+        '<default remote="default-remote" revision="refs/heads/main"/>'
+        '<project name="platform/art" path="art" revision="ABCDEF" '
+        'groups="notdefault,platform-' + self.platform + '"/>'
+        '<superproject name="superproject"/>'
         '</manifest>')
 
   def test_superproject_update_project_revision_id(self):
@@ -168,13 +168,57 @@
             manifest_xml = fp.read()
           self.assertEqual(
               manifest_xml,
-              '<?xml version="1.0" ?><manifest>' +
-              '<remote name="default-remote" fetch="http://localhost"/>' +
-              '<default remote="default-remote" revision="refs/heads/main"/>' +
-              '<project name="platform/art" path="art" ' +
-              'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" ' +
-              'groups="notdefault,platform-' + self.platform + '"/>' +
-              '<superproject name="superproject"/>' +
+              '<?xml version="1.0" ?><manifest>'
+              '<remote name="default-remote" fetch="http://localhost"/>'
+              '<default remote="default-remote" revision="refs/heads/main"/>'
+              '<project name="platform/art" path="art" '
+              'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" '
+              'groups="notdefault,platform-' + self.platform + '"/>'
+              '<superproject name="superproject"/>'
+              '</manifest>')
+
+  def test_superproject_update_project_revision_id_with_different_remotes(self):
+    """Test update of commit ids of a manifest with mutiple remotes."""
+    manifest = self.getXmlManifest("""
+<manifest>
+  <remote name="default-remote" fetch="http://localhost" />
+  <remote name="goog" fetch="http://localhost2" />
+  <default remote="default-remote" revision="refs/heads/main" />
+  <superproject name="superproject"/>
+  <project path="vendor/x" name="platform/vendor/x" remote="goog" groups="vendor"
+           revision="master-with-vendor" clone-depth="1" />
+  <project path="art" name="platform/art" groups="notdefault,platform-""" + self.platform + """
+  " /></manifest>
+""")
+    self.maxDiff = None
+    self._superproject = git_superproject.Superproject(manifest, self.repodir)
+    self.assertEqual(len(self._superproject._manifest.projects), 2)
+    projects = self._superproject._manifest.projects
+    data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00'
+            '160000 commit e9d25da64d8d365dbba7c8ee00fe8c4473fe9a06\tbootable/recovery\x00')
+    with mock.patch.object(self._superproject, '_Init', return_value=True):
+      with mock.patch.object(self._superproject, '_Fetch', return_value=True):
+        with mock.patch.object(self._superproject,
+                               '_LsTree',
+                               return_value=data):
+          # Create temporary directory so that it can write the file.
+          os.mkdir(self._superproject._superproject_path)
+          manifest_path = self._superproject.UpdateProjectsRevisionId(projects)
+          self.assertIsNotNone(manifest_path)
+          with open(manifest_path, 'r') as fp:
+            manifest_xml = fp.read()
+          self.assertEqual(
+              manifest_xml,
+              '<?xml version="1.0" ?><manifest>'
+              '<remote name="default-remote" fetch="http://localhost"/>'
+              '<remote name="goog" fetch="http://localhost2"/>'
+              '<default remote="default-remote" revision="refs/heads/main"/>'
+              '<project name="platform/art" path="art" '
+              'revision="2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea" '
+              'groups="notdefault,platform-' + self.platform + '"/>'
+              '<project name="platform/vendor/x" path="vendor/x" remote="goog" '
+              'revision="master-with-vendor" groups="vendor" clone-depth="1"/>'
+              '<superproject name="superproject"/>'
               '</manifest>')