diff options
| -rw-r--r-- | git_superproject.py | 69 | ||||
| -rw-r--r-- | manifest_xml.py | 47 | ||||
| -rw-r--r-- | project.py | 1 | ||||
| -rw-r--r-- | subcmds/init.py | 1 | ||||
| -rw-r--r-- | subcmds/sync.py | 11 | ||||
| -rw-r--r-- | tests/test_git_superproject.py | 63 | ||||
| -rw-r--r-- | tests/test_manifest_xml.py | 50 |
7 files changed, 125 insertions, 117 deletions
diff --git a/git_superproject.py b/git_superproject.py index f4dbb27b..9f585e5d 100644 --- a/git_superproject.py +++ b/git_superproject.py | |||
| @@ -71,42 +71,50 @@ class Superproject(object): | |||
| 71 | lookup of commit ids for all projects. It contains _project_commit_ids which | 71 | lookup of commit ids for all projects. It contains _project_commit_ids which |
| 72 | is a dictionary with project/commit id entries. | 72 | is a dictionary with project/commit id entries. |
| 73 | """ | 73 | """ |
| 74 | def __init__(self, manifest, repodir, git_event_log, | 74 | def __init__(self, manifest, name, remote, revision, |
| 75 | superproject_dir='exp-superproject', quiet=False, print_messages=False): | 75 | superproject_dir='exp-superproject'): |
| 76 | """Initializes superproject. | 76 | """Initializes superproject. |
| 77 | 77 | ||
| 78 | Args: | 78 | Args: |
| 79 | manifest: A Manifest object that is to be written to a file. | 79 | manifest: A Manifest object that is to be written to a file. |
| 80 | repodir: Path to the .repo/ dir for holding all internal checkout state. | 80 | name: The unique name of the superproject |
| 81 | It must be in the top directory of the repo client checkout. | 81 | remote: The RemoteSpec for the remote. |
| 82 | git_event_log: A git trace2 event log to log events. | 82 | revision: The name of the git branch to track. |
| 83 | superproject_dir: Relative path under |repodir| to checkout superproject. | 83 | superproject_dir: Relative path under |manifest.subdir| to checkout |
| 84 | quiet: If True then only print the progress messages. | 84 | superproject. |
| 85 | print_messages: if True then print error/warning messages. | ||
| 86 | """ | 85 | """ |
| 87 | self._project_commit_ids = None | 86 | self._project_commit_ids = None |
| 88 | self._manifest = manifest | 87 | self._manifest = manifest |
| 89 | self._git_event_log = git_event_log | 88 | self.name = name |
| 90 | self._quiet = quiet | 89 | self.remote = remote |
| 91 | self._print_messages = print_messages | 90 | self.revision = self._branch = revision |
| 92 | self._branch = manifest.branch | 91 | self._repodir = manifest.repodir |
| 93 | self._repodir = os.path.abspath(repodir) | ||
| 94 | self._superproject_dir = superproject_dir | 92 | self._superproject_dir = superproject_dir |
| 95 | self._superproject_path = manifest.SubmanifestInfoDir(manifest.path_prefix, | 93 | self._superproject_path = manifest.SubmanifestInfoDir(manifest.path_prefix, |
| 96 | superproject_dir) | 94 | superproject_dir) |
| 97 | self._manifest_path = os.path.join(self._superproject_path, | 95 | self._manifest_path = os.path.join(self._superproject_path, |
| 98 | _SUPERPROJECT_MANIFEST_NAME) | 96 | _SUPERPROJECT_MANIFEST_NAME) |
| 99 | git_name = '' | 97 | git_name = hashlib.md5(remote.name.encode('utf8')).hexdigest() + '-' |
| 100 | if self._manifest.superproject: | 98 | self._remote_url = remote.url |
| 101 | remote = self._manifest.superproject['remote'] | ||
| 102 | git_name = hashlib.md5(remote.name.encode('utf8')).hexdigest() + '-' | ||
| 103 | self._branch = self._manifest.superproject['revision'] | ||
| 104 | self._remote_url = remote.url | ||
| 105 | else: | ||
| 106 | self._remote_url = None | ||
| 107 | self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME | 99 | self._work_git_name = git_name + _SUPERPROJECT_GIT_NAME |
| 108 | self._work_git = os.path.join(self._superproject_path, self._work_git_name) | 100 | self._work_git = os.path.join(self._superproject_path, self._work_git_name) |
| 109 | 101 | ||
| 102 | # The following are command arguemnts, rather then superproject attributes, | ||
| 103 | # and where included here originally. They should eventually become | ||
| 104 | # arguments that are passed down from the public methods, instead of being | ||
| 105 | # treated as attributes. | ||
| 106 | self._git_event_log = None | ||
| 107 | self._quiet = False | ||
| 108 | self._print_messages = False | ||
| 109 | |||
| 110 | def SetQuiet(self, value): | ||
| 111 | """Set the _quiet attribute.""" | ||
| 112 | self._quiet = value | ||
| 113 | |||
| 114 | def SetPrintMessages(self, value): | ||
| 115 | """Set the _print_messages attribute.""" | ||
| 116 | self._print_messages = value | ||
| 117 | |||
| 110 | @property | 118 | @property |
| 111 | def project_commit_ids(self): | 119 | def project_commit_ids(self): |
| 112 | """Returns a dictionary of projects and their commit ids.""" | 120 | """Returns a dictionary of projects and their commit ids.""" |
| @@ -215,12 +223,16 @@ class Superproject(object): | |||
| 215 | f'return code: {retval}, stderr: {p.stderr}') | 223 | f'return code: {retval}, stderr: {p.stderr}') |
| 216 | return data | 224 | return data |
| 217 | 225 | ||
| 218 | def Sync(self): | 226 | def Sync(self, git_event_log): |
| 219 | """Gets a local copy of a superproject for the manifest. | 227 | """Gets a local copy of a superproject for the manifest. |
| 220 | 228 | ||
| 229 | Args: | ||
| 230 | git_event_log: an EventLog, for git tracing. | ||
| 231 | |||
| 221 | Returns: | 232 | Returns: |
| 222 | SyncResult | 233 | SyncResult |
| 223 | """ | 234 | """ |
| 235 | self._git_event_log = git_event_log | ||
| 224 | if not self._manifest.superproject: | 236 | if not self._manifest.superproject: |
| 225 | self._LogWarning(f'superproject tag is not defined in manifest: ' | 237 | self._LogWarning(f'superproject tag is not defined in manifest: ' |
| 226 | f'{self._manifest.manifestFile}') | 238 | f'{self._manifest.manifestFile}') |
| @@ -248,7 +260,7 @@ class Superproject(object): | |||
| 248 | Returns: | 260 | Returns: |
| 249 | CommitIdsResult | 261 | CommitIdsResult |
| 250 | """ | 262 | """ |
| 251 | sync_result = self.Sync() | 263 | sync_result = self.Sync(self._git_event_log) |
| 252 | if not sync_result.success: | 264 | if not sync_result.success: |
| 253 | return CommitIdsResult(None, sync_result.fatal) | 265 | return CommitIdsResult(None, sync_result.fatal) |
| 254 | 266 | ||
| @@ -313,7 +325,7 @@ class Superproject(object): | |||
| 313 | # Skip the project if it comes from the local manifest. | 325 | # Skip the project if it comes from the local manifest. |
| 314 | return project.manifest.IsFromLocalManifest(project) | 326 | return project.manifest.IsFromLocalManifest(project) |
| 315 | 327 | ||
| 316 | def UpdateProjectsRevisionId(self, projects): | 328 | def UpdateProjectsRevisionId(self, projects, git_event_log): |
| 317 | """Update revisionId of every project in projects with the commit id. | 329 | """Update revisionId of every project in projects with the commit id. |
| 318 | 330 | ||
| 319 | Args: | 331 | Args: |
| @@ -322,6 +334,7 @@ class Superproject(object): | |||
| 322 | Returns: | 334 | Returns: |
| 323 | UpdateProjectsResult | 335 | UpdateProjectsResult |
| 324 | """ | 336 | """ |
| 337 | self._git_event_log = git_event_log | ||
| 325 | commit_ids_result = self._GetAllProjectsCommitIds() | 338 | commit_ids_result = self._GetAllProjectsCommitIds() |
| 326 | commit_ids = commit_ids_result.commit_ids | 339 | commit_ids = commit_ids_result.commit_ids |
| 327 | if not commit_ids: | 340 | if not commit_ids: |
| @@ -397,7 +410,7 @@ def _UseSuperprojectFromConfiguration(): | |||
| 397 | 410 | ||
| 398 | def PrintMessages(opt, manifest): | 411 | def PrintMessages(opt, manifest): |
| 399 | """Returns a boolean if error/warning messages are to be printed.""" | 412 | """Returns a boolean if error/warning messages are to be printed.""" |
| 400 | return opt.use_superproject is not None or manifest.superproject | 413 | return opt.use_superproject is not None or bool(manifest.superproject) |
| 401 | 414 | ||
| 402 | 415 | ||
| 403 | def UseSuperproject(opt, manifest): | 416 | def UseSuperproject(opt, manifest): |
| @@ -409,7 +422,7 @@ def UseSuperproject(opt, manifest): | |||
| 409 | client_value = manifest.manifestProject.use_superproject | 422 | client_value = manifest.manifestProject.use_superproject |
| 410 | if client_value is not None: | 423 | if client_value is not None: |
| 411 | return client_value | 424 | return client_value |
| 412 | else: | 425 | elif manifest.superproject: |
| 413 | if not manifest.superproject: | ||
| 414 | return False | ||
| 415 | return _UseSuperprojectFromConfiguration() | 426 | return _UseSuperprojectFromConfiguration() |
| 427 | else: | ||
| 428 | return False | ||
diff --git a/manifest_xml.py b/manifest_xml.py index 8718dc54..7d19d63e 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
| @@ -24,6 +24,7 @@ import urllib.parse | |||
| 24 | import gitc_utils | 24 | import gitc_utils |
| 25 | from git_config import GitConfig, IsId | 25 | from git_config import GitConfig, IsId |
| 26 | from git_refs import R_HEADS, HEAD | 26 | from git_refs import R_HEADS, HEAD |
| 27 | from git_superproject import Superproject | ||
| 27 | import platform_utils | 28 | import platform_utils |
| 28 | from project import (Annotation, RemoteSpec, Project, RepoProject, | 29 | from project import (Annotation, RemoteSpec, Project, RepoProject, |
| 29 | ManifestProject) | 30 | ManifestProject) |
| @@ -670,17 +671,17 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 670 | if self._superproject: | 671 | if self._superproject: |
| 671 | root.appendChild(doc.createTextNode('')) | 672 | root.appendChild(doc.createTextNode('')) |
| 672 | e = doc.createElement('superproject') | 673 | e = doc.createElement('superproject') |
| 673 | e.setAttribute('name', self._superproject['name']) | 674 | e.setAttribute('name', self._superproject.name) |
| 674 | remoteName = None | 675 | remoteName = None |
| 675 | if d.remote: | 676 | if d.remote: |
| 676 | remoteName = d.remote.name | 677 | remoteName = d.remote.name |
| 677 | remote = self._superproject.get('remote') | 678 | remote = self._superproject.remote |
| 678 | if not d.remote or remote.orig_name != remoteName: | 679 | if not d.remote or remote.orig_name != remoteName: |
| 679 | remoteName = remote.orig_name | 680 | remoteName = remote.orig_name |
| 680 | e.setAttribute('remote', remoteName) | 681 | e.setAttribute('remote', remoteName) |
| 681 | revision = remote.revision or d.revisionExpr | 682 | revision = remote.revision or d.revisionExpr |
| 682 | if not revision or revision != self._superproject['revision']: | 683 | if not revision or revision != self._superproject.revision: |
| 683 | e.setAttribute('revision', self._superproject['revision']) | 684 | e.setAttribute('revision', self._superproject.revision) |
| 684 | root.appendChild(e) | 685 | root.appendChild(e) |
| 685 | 686 | ||
| 686 | if self._contactinfo.bugurl != Wrapper().BUG_URL: | 687 | if self._contactinfo.bugurl != Wrapper().BUG_URL: |
| @@ -984,7 +985,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 984 | self._default = None | 985 | self._default = None |
| 985 | self._submanifests = {} | 986 | self._submanifests = {} |
| 986 | self._repo_hooks_project = None | 987 | self._repo_hooks_project = None |
| 987 | self._superproject = {} | 988 | self._superproject = None |
| 988 | self._contactinfo = ContactInfo(Wrapper().BUG_URL) | 989 | self._contactinfo = ContactInfo(Wrapper().BUG_URL) |
| 989 | self._notice = None | 990 | self._notice = None |
| 990 | self.branch = None | 991 | self.branch = None |
| @@ -1052,20 +1053,19 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 1052 | 1053 | ||
| 1053 | # Now that we have loaded this manifest, load any submanifest manifests | 1054 | # Now that we have loaded this manifest, load any submanifest manifests |
| 1054 | # as well. We need to do this after self._loaded is set to avoid looping. | 1055 | # as well. We need to do this after self._loaded is set to avoid looping. |
| 1055 | if self._outer_client: | 1056 | for name in self._submanifests: |
| 1056 | for name in self._submanifests: | 1057 | tree = self._submanifests[name] |
| 1057 | tree = self._submanifests[name] | 1058 | spec = tree.ToSubmanifestSpec(self) |
| 1058 | spec = tree.ToSubmanifestSpec(self) | 1059 | present = os.path.exists(os.path.join(self.subdir, MANIFEST_FILE_NAME)) |
| 1059 | present = os.path.exists(os.path.join(self.subdir, MANIFEST_FILE_NAME)) | 1060 | if present and tree.present and not tree.repo_client: |
| 1060 | if present and tree.present and not tree.repo_client: | 1061 | if initial_client and initial_client.topdir == self.topdir: |
| 1061 | if initial_client and initial_client.topdir == self.topdir: | 1062 | tree.repo_client = self |
| 1062 | tree.repo_client = self | 1063 | tree.present = present |
| 1063 | tree.present = present | 1064 | elif not os.path.exists(self.subdir): |
| 1064 | elif not os.path.exists(self.subdir): | 1065 | tree.present = False |
| 1065 | tree.present = False | 1066 | if present and tree.present: |
| 1066 | if present and tree.present: | 1067 | tree.repo_client._Load(initial_client=initial_client, |
| 1067 | tree.repo_client._Load(initial_client=initial_client, | 1068 | submanifest_depth=submanifest_depth + 1) |
| 1068 | submanifest_depth=submanifest_depth + 1) | ||
| 1069 | 1069 | ||
| 1070 | def _ParseManifestXml(self, path, include_root, parent_groups='', | 1070 | def _ParseManifestXml(self, path, include_root, parent_groups='', |
| 1071 | restrict_includes=True): | 1071 | restrict_includes=True): |
| @@ -1267,11 +1267,10 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 1267 | if node.nodeName == 'superproject': | 1267 | if node.nodeName == 'superproject': |
| 1268 | name = self._reqatt(node, 'name') | 1268 | name = self._reqatt(node, 'name') |
| 1269 | # There can only be one superproject. | 1269 | # There can only be one superproject. |
| 1270 | if self._superproject.get('name'): | 1270 | if self._superproject: |
| 1271 | raise ManifestParseError( | 1271 | raise ManifestParseError( |
| 1272 | 'duplicate superproject in %s' % | 1272 | 'duplicate superproject in %s' % |
| 1273 | (self.manifestFile)) | 1273 | (self.manifestFile)) |
| 1274 | self._superproject['name'] = name | ||
| 1275 | remote_name = node.getAttribute('remote') | 1274 | remote_name = node.getAttribute('remote') |
| 1276 | if not remote_name: | 1275 | if not remote_name: |
| 1277 | remote = self._default.remote | 1276 | remote = self._default.remote |
| @@ -1280,14 +1279,16 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 1280 | if remote is None: | 1279 | if remote is None: |
| 1281 | raise ManifestParseError("no remote for superproject %s within %s" % | 1280 | raise ManifestParseError("no remote for superproject %s within %s" % |
| 1282 | (name, self.manifestFile)) | 1281 | (name, self.manifestFile)) |
| 1283 | self._superproject['remote'] = remote.ToRemoteSpec(name) | ||
| 1284 | revision = node.getAttribute('revision') or remote.revision | 1282 | revision = node.getAttribute('revision') or remote.revision |
| 1285 | if not revision: | 1283 | if not revision: |
| 1286 | revision = self._default.revisionExpr | 1284 | revision = self._default.revisionExpr |
| 1287 | if not revision: | 1285 | if not revision: |
| 1288 | raise ManifestParseError('no revision for superproject %s within %s' % | 1286 | raise ManifestParseError('no revision for superproject %s within %s' % |
| 1289 | (name, self.manifestFile)) | 1287 | (name, self.manifestFile)) |
| 1290 | self._superproject['revision'] = revision | 1288 | self._superproject = Superproject(self, |
| 1289 | name=name, | ||
| 1290 | remote=remote.ToRemoteSpec(name), | ||
| 1291 | revision=revision) | ||
| 1291 | if node.nodeName == 'contactinfo': | 1292 | if node.nodeName == 'contactinfo': |
| 1292 | bugurl = self._reqatt(node, 'bugurl') | 1293 | bugurl = self._reqatt(node, 'bugurl') |
| 1293 | # This element can be repeated, later entries will clobber earlier ones. | 1294 | # This element can be repeated, later entries will clobber earlier ones. |
| @@ -36,7 +36,6 @@ from git_trace2_event_log import EventLog | |||
| 36 | from error import GitError, UploadError, DownloadError | 36 | from error import GitError, UploadError, DownloadError |
| 37 | from error import ManifestInvalidRevisionError, ManifestInvalidPathError | 37 | from error import ManifestInvalidRevisionError, ManifestInvalidPathError |
| 38 | from error import NoManifestException, ManifestParseError | 38 | from error import NoManifestException, ManifestParseError |
| 39 | from git_superproject import Superproject | ||
| 40 | import platform_utils | 39 | import platform_utils |
| 41 | import progress | 40 | import progress |
| 42 | from repo_trace import IsTrace, Trace | 41 | from repo_trace import IsTrace, Trace |
diff --git a/subcmds/init.py b/subcmds/init.py index 65b63efd..99f30dce 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
| @@ -25,7 +25,6 @@ from project import SyncBuffer | |||
| 25 | from git_config import GitConfig | 25 | from git_config import GitConfig |
| 26 | from git_command import git_require, MIN_GIT_VERSION_SOFT, MIN_GIT_VERSION_HARD | 26 | from git_command import git_require, MIN_GIT_VERSION_SOFT, MIN_GIT_VERSION_HARD |
| 27 | import fetch | 27 | import fetch |
| 28 | import git_superproject | ||
| 29 | import platform_utils | 28 | import platform_utils |
| 30 | from wrapper import Wrapper | 29 | from wrapper import Wrapper |
| 31 | 30 | ||
diff --git a/subcmds/sync.py b/subcmds/sync.py index 9e783205..4d0a5ec6 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -304,12 +304,10 @@ later is required to fix a server side protocol bug. | |||
| 304 | Returns: | 304 | Returns: |
| 305 | Returns path to the overriding manifest file instead of None. | 305 | Returns path to the overriding manifest file instead of None. |
| 306 | """ | 306 | """ |
| 307 | superproject = self.manifest.superproject | ||
| 308 | superproject.SetQuiet(opt.quiet) | ||
| 307 | print_messages = git_superproject.PrintMessages(opt, self.manifest) | 309 | print_messages = git_superproject.PrintMessages(opt, self.manifest) |
| 308 | superproject = git_superproject.Superproject(self.manifest, | 310 | superproject.SetPrintMessages(print_messages) |
| 309 | self.repodir, | ||
| 310 | self.git_event_log, | ||
| 311 | quiet=opt.quiet, | ||
| 312 | print_messages=print_messages) | ||
| 313 | if opt.local_only: | 311 | if opt.local_only: |
| 314 | manifest_path = superproject.manifest_path | 312 | manifest_path = superproject.manifest_path |
| 315 | if manifest_path: | 313 | if manifest_path: |
| @@ -319,7 +317,8 @@ later is required to fix a server side protocol bug. | |||
| 319 | all_projects = self.GetProjects(args, | 317 | all_projects = self.GetProjects(args, |
| 320 | missing_ok=True, | 318 | missing_ok=True, |
| 321 | submodules_ok=opt.fetch_submodules) | 319 | submodules_ok=opt.fetch_submodules) |
| 322 | update_result = superproject.UpdateProjectsRevisionId(all_projects) | 320 | update_result = superproject.UpdateProjectsRevisionId( |
| 321 | all_projects, git_event_log=self.git_event_log) | ||
| 323 | manifest_path = update_result.manifest_path | 322 | manifest_path = update_result.manifest_path |
| 324 | superproject_logging_data['updatedrevisionid'] = bool(manifest_path) | 323 | superproject_logging_data['updatedrevisionid'] = bool(manifest_path) |
| 325 | if manifest_path: | 324 | if manifest_path: |
diff --git a/tests/test_git_superproject.py b/tests/test_git_superproject.py index a24fc7f0..1e7b1201 100644 --- a/tests/test_git_superproject.py +++ b/tests/test_git_superproject.py | |||
| @@ -68,8 +68,10 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 68 | <project path="art" name="platform/art" groups="notdefault,platform-""" + self.platform + """ | 68 | <project path="art" name="platform/art" groups="notdefault,platform-""" + self.platform + """ |
| 69 | " /></manifest> | 69 | " /></manifest> |
| 70 | """) | 70 | """) |
| 71 | self._superproject = git_superproject.Superproject(manifest, self.repodir, | 71 | self._superproject = git_superproject.Superproject( |
| 72 | self.git_event_log) | 72 | manifest, name='superproject', |
| 73 | remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'), | ||
| 74 | revision='refs/heads/main') | ||
| 73 | 75 | ||
| 74 | def tearDown(self): | 76 | def tearDown(self): |
| 75 | """Tear down superproject every time.""" | 77 | """Tear down superproject every time.""" |
| @@ -125,12 +127,7 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 125 | <manifest> | 127 | <manifest> |
| 126 | </manifest> | 128 | </manifest> |
| 127 | """) | 129 | """) |
| 128 | superproject = git_superproject.Superproject(manifest, self.repodir, self.git_event_log) | 130 | self.assertIsNone(manifest.superproject) |
| 129 | # Test that exit condition is false when there is no superproject tag. | ||
| 130 | sync_result = superproject.Sync() | ||
| 131 | self.assertFalse(sync_result.success) | ||
| 132 | self.assertFalse(sync_result.fatal) | ||
| 133 | self.verifyErrorEvent() | ||
| 134 | 131 | ||
| 135 | def test_superproject_get_superproject_invalid_url(self): | 132 | def test_superproject_get_superproject_invalid_url(self): |
| 136 | """Test with an invalid url.""" | 133 | """Test with an invalid url.""" |
| @@ -141,8 +138,11 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 141 | <superproject name="superproject"/> | 138 | <superproject name="superproject"/> |
| 142 | </manifest> | 139 | </manifest> |
| 143 | """) | 140 | """) |
| 144 | superproject = git_superproject.Superproject(manifest, self.repodir, self.git_event_log) | 141 | superproject = git_superproject.Superproject( |
| 145 | sync_result = superproject.Sync() | 142 | manifest, name='superproject', |
| 143 | remote=manifest.remotes.get('test-remote').ToRemoteSpec('superproject'), | ||
| 144 | revision='refs/heads/main') | ||
| 145 | sync_result = superproject.Sync(self.git_event_log) | ||
| 146 | self.assertFalse(sync_result.success) | 146 | self.assertFalse(sync_result.success) |
| 147 | self.assertTrue(sync_result.fatal) | 147 | self.assertTrue(sync_result.fatal) |
| 148 | 148 | ||
| @@ -155,17 +155,19 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 155 | <superproject name="superproject"/> | 155 | <superproject name="superproject"/> |
| 156 | </manifest> | 156 | </manifest> |
| 157 | """) | 157 | """) |
| 158 | self._superproject = git_superproject.Superproject(manifest, self.repodir, | 158 | self._superproject = git_superproject.Superproject( |
| 159 | self.git_event_log) | 159 | manifest, name='superproject', |
| 160 | remote=manifest.remotes.get('test-remote').ToRemoteSpec('superproject'), | ||
| 161 | revision='refs/heads/main') | ||
| 160 | with mock.patch.object(self._superproject, '_branch', 'junk'): | 162 | with mock.patch.object(self._superproject, '_branch', 'junk'): |
| 161 | sync_result = self._superproject.Sync() | 163 | sync_result = self._superproject.Sync(self.git_event_log) |
| 162 | self.assertFalse(sync_result.success) | 164 | self.assertFalse(sync_result.success) |
| 163 | self.assertTrue(sync_result.fatal) | 165 | self.assertTrue(sync_result.fatal) |
| 164 | 166 | ||
| 165 | def test_superproject_get_superproject_mock_init(self): | 167 | def test_superproject_get_superproject_mock_init(self): |
| 166 | """Test with _Init failing.""" | 168 | """Test with _Init failing.""" |
| 167 | with mock.patch.object(self._superproject, '_Init', return_value=False): | 169 | with mock.patch.object(self._superproject, '_Init', return_value=False): |
| 168 | sync_result = self._superproject.Sync() | 170 | sync_result = self._superproject.Sync(self.git_event_log) |
| 169 | self.assertFalse(sync_result.success) | 171 | self.assertFalse(sync_result.success) |
| 170 | self.assertTrue(sync_result.fatal) | 172 | self.assertTrue(sync_result.fatal) |
| 171 | 173 | ||
| @@ -174,7 +176,7 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 174 | with mock.patch.object(self._superproject, '_Init', return_value=True): | 176 | with mock.patch.object(self._superproject, '_Init', return_value=True): |
| 175 | os.mkdir(self._superproject._superproject_path) | 177 | os.mkdir(self._superproject._superproject_path) |
| 176 | with mock.patch.object(self._superproject, '_Fetch', return_value=False): | 178 | with mock.patch.object(self._superproject, '_Fetch', return_value=False): |
| 177 | sync_result = self._superproject.Sync() | 179 | sync_result = self._superproject.Sync(self.git_event_log) |
| 178 | self.assertFalse(sync_result.success) | 180 | self.assertFalse(sync_result.success) |
| 179 | self.assertTrue(sync_result.fatal) | 181 | self.assertTrue(sync_result.fatal) |
| 180 | 182 | ||
| @@ -230,7 +232,7 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 230 | return_value=data): | 232 | return_value=data): |
| 231 | # Create temporary directory so that it can write the file. | 233 | # Create temporary directory so that it can write the file. |
| 232 | os.mkdir(self._superproject._superproject_path) | 234 | os.mkdir(self._superproject._superproject_path) |
| 233 | update_result = self._superproject.UpdateProjectsRevisionId(projects) | 235 | update_result = self._superproject.UpdateProjectsRevisionId(projects, self.git_event_log) |
| 234 | self.assertIsNotNone(update_result.manifest_path) | 236 | self.assertIsNotNone(update_result.manifest_path) |
| 235 | self.assertFalse(update_result.fatal) | 237 | self.assertFalse(update_result.fatal) |
| 236 | with open(update_result.manifest_path, 'r') as fp: | 238 | with open(update_result.manifest_path, 'r') as fp: |
| @@ -256,22 +258,13 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 256 | </manifest> | 258 | </manifest> |
| 257 | """) | 259 | """) |
| 258 | self.maxDiff = None | 260 | self.maxDiff = None |
| 259 | self._superproject = git_superproject.Superproject(manifest, self.repodir, | 261 | self.assertIsNone(manifest.superproject) |
| 260 | self.git_event_log) | ||
| 261 | self.assertEqual(len(self._superproject._manifest.projects), 1) | ||
| 262 | projects = self._superproject._manifest.projects | ||
| 263 | project = projects[0] | ||
| 264 | project.SetRevisionId('ABCDEF') | ||
| 265 | update_result = self._superproject.UpdateProjectsRevisionId(projects) | ||
| 266 | self.assertIsNone(update_result.manifest_path) | ||
| 267 | self.assertFalse(update_result.fatal) | ||
| 268 | self.verifyErrorEvent() | ||
| 269 | self.assertEqual( | 262 | self.assertEqual( |
| 270 | sort_attributes(manifest.ToXml().toxml()), | 263 | sort_attributes(manifest.ToXml().toxml()), |
| 271 | '<?xml version="1.0" ?><manifest>' | 264 | '<?xml version="1.0" ?><manifest>' |
| 272 | '<remote fetch="http://localhost" name="default-remote"/>' | 265 | '<remote fetch="http://localhost" name="default-remote"/>' |
| 273 | '<default remote="default-remote" revision="refs/heads/main"/>' | 266 | '<default remote="default-remote" revision="refs/heads/main"/>' |
| 274 | '<project name="test-name" revision="ABCDEF" upstream="refs/heads/main"/>' | 267 | '<project name="test-name"/>' |
| 275 | '</manifest>') | 268 | '</manifest>') |
| 276 | 269 | ||
| 277 | def test_superproject_update_project_revision_id_from_local_manifest_group(self): | 270 | def test_superproject_update_project_revision_id_from_local_manifest_group(self): |
| @@ -290,8 +283,10 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 290 | " /></manifest> | 283 | " /></manifest> |
| 291 | """) | 284 | """) |
| 292 | self.maxDiff = None | 285 | self.maxDiff = None |
| 293 | self._superproject = git_superproject.Superproject(manifest, self.repodir, | 286 | self._superproject = git_superproject.Superproject( |
| 294 | self.git_event_log) | 287 | manifest, name='superproject', |
| 288 | remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'), | ||
| 289 | revision='refs/heads/main') | ||
| 295 | self.assertEqual(len(self._superproject._manifest.projects), 2) | 290 | self.assertEqual(len(self._superproject._manifest.projects), 2) |
| 296 | projects = self._superproject._manifest.projects | 291 | projects = self._superproject._manifest.projects |
| 297 | data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00') | 292 | data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00') |
| @@ -302,7 +297,7 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 302 | return_value=data): | 297 | return_value=data): |
| 303 | # Create temporary directory so that it can write the file. | 298 | # Create temporary directory so that it can write the file. |
| 304 | os.mkdir(self._superproject._superproject_path) | 299 | os.mkdir(self._superproject._superproject_path) |
| 305 | update_result = self._superproject.UpdateProjectsRevisionId(projects) | 300 | update_result = self._superproject.UpdateProjectsRevisionId(projects, self.git_event_log) |
| 306 | self.assertIsNotNone(update_result.manifest_path) | 301 | self.assertIsNotNone(update_result.manifest_path) |
| 307 | self.assertFalse(update_result.fatal) | 302 | self.assertFalse(update_result.fatal) |
| 308 | with open(update_result.manifest_path, 'r') as fp: | 303 | with open(update_result.manifest_path, 'r') as fp: |
| @@ -337,8 +332,10 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 337 | " /></manifest> | 332 | " /></manifest> |
| 338 | """) | 333 | """) |
| 339 | self.maxDiff = None | 334 | self.maxDiff = None |
| 340 | self._superproject = git_superproject.Superproject(manifest, self.repodir, | 335 | self._superproject = git_superproject.Superproject( |
| 341 | self.git_event_log) | 336 | manifest, name='superproject', |
| 337 | remote=manifest.remotes.get('default-remote').ToRemoteSpec('superproject'), | ||
| 338 | revision='refs/heads/main') | ||
| 342 | self.assertEqual(len(self._superproject._manifest.projects), 3) | 339 | self.assertEqual(len(self._superproject._manifest.projects), 3) |
| 343 | projects = self._superproject._manifest.projects | 340 | projects = self._superproject._manifest.projects |
| 344 | data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' | 341 | data = ('160000 commit 2c2724cb36cd5a9cec6c852c681efc3b7c6b86ea\tart\x00' |
| @@ -350,7 +347,7 @@ class SuperprojectTestCase(unittest.TestCase): | |||
| 350 | return_value=data): | 347 | return_value=data): |
| 351 | # Create temporary directory so that it can write the file. | 348 | # Create temporary directory so that it can write the file. |
| 352 | os.mkdir(self._superproject._superproject_path) | 349 | os.mkdir(self._superproject._superproject_path) |
| 353 | update_result = self._superproject.UpdateProjectsRevisionId(projects) | 350 | update_result = self._superproject.UpdateProjectsRevisionId(projects, self.git_event_log) |
| 354 | self.assertIsNotNone(update_result.manifest_path) | 351 | self.assertIsNotNone(update_result.manifest_path) |
| 355 | self.assertFalse(update_result.fatal) | 352 | self.assertFalse(update_result.fatal) |
| 356 | with open(update_result.manifest_path, 'r') as fp: | 353 | with open(update_result.manifest_path, 'r') as fp: |
diff --git a/tests/test_manifest_xml.py b/tests/test_manifest_xml.py index cb3eb855..ede41547 100644 --- a/tests/test_manifest_xml.py +++ b/tests/test_manifest_xml.py | |||
| @@ -289,8 +289,8 @@ class XmlManifestTests(ManifestParseTestCase): | |||
| 289 | <x-custom-tag>X tags are always ignored</x-custom-tag> | 289 | <x-custom-tag>X tags are always ignored</x-custom-tag> |
| 290 | </manifest> | 290 | </manifest> |
| 291 | """) | 291 | """) |
| 292 | self.assertEqual(manifest.superproject['name'], 'superproject') | 292 | self.assertEqual(manifest.superproject.name, 'superproject') |
| 293 | self.assertEqual(manifest.superproject['remote'].name, 'test-remote') | 293 | self.assertEqual(manifest.superproject.remote.name, 'test-remote') |
| 294 | self.assertEqual( | 294 | self.assertEqual( |
| 295 | sort_attributes(manifest.ToXml().toxml()), | 295 | sort_attributes(manifest.ToXml().toxml()), |
| 296 | '<?xml version="1.0" ?><manifest>' | 296 | '<?xml version="1.0" ?><manifest>' |
| @@ -569,10 +569,10 @@ class SuperProjectElementTests(ManifestParseTestCase): | |||
| 569 | <superproject name="superproject"/> | 569 | <superproject name="superproject"/> |
| 570 | </manifest> | 570 | </manifest> |
| 571 | """) | 571 | """) |
| 572 | self.assertEqual(manifest.superproject['name'], 'superproject') | 572 | self.assertEqual(manifest.superproject.name, 'superproject') |
| 573 | self.assertEqual(manifest.superproject['remote'].name, 'test-remote') | 573 | self.assertEqual(manifest.superproject.remote.name, 'test-remote') |
| 574 | self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject') | 574 | self.assertEqual(manifest.superproject.remote.url, 'http://localhost/superproject') |
| 575 | self.assertEqual(manifest.superproject['revision'], 'refs/heads/main') | 575 | self.assertEqual(manifest.superproject.revision, 'refs/heads/main') |
| 576 | self.assertEqual( | 576 | self.assertEqual( |
| 577 | sort_attributes(manifest.ToXml().toxml()), | 577 | sort_attributes(manifest.ToXml().toxml()), |
| 578 | '<?xml version="1.0" ?><manifest>' | 578 | '<?xml version="1.0" ?><manifest>' |
| @@ -591,10 +591,10 @@ class SuperProjectElementTests(ManifestParseTestCase): | |||
| 591 | <superproject name="superproject" revision="refs/heads/stable" /> | 591 | <superproject name="superproject" revision="refs/heads/stable" /> |
| 592 | </manifest> | 592 | </manifest> |
| 593 | """) | 593 | """) |
| 594 | self.assertEqual(manifest.superproject['name'], 'superproject') | 594 | self.assertEqual(manifest.superproject.name, 'superproject') |
| 595 | self.assertEqual(manifest.superproject['remote'].name, 'test-remote') | 595 | self.assertEqual(manifest.superproject.remote.name, 'test-remote') |
| 596 | self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject') | 596 | self.assertEqual(manifest.superproject.remote.url, 'http://localhost/superproject') |
| 597 | self.assertEqual(manifest.superproject['revision'], 'refs/heads/stable') | 597 | self.assertEqual(manifest.superproject.revision, 'refs/heads/stable') |
| 598 | self.assertEqual( | 598 | self.assertEqual( |
| 599 | sort_attributes(manifest.ToXml().toxml()), | 599 | sort_attributes(manifest.ToXml().toxml()), |
| 600 | '<?xml version="1.0" ?><manifest>' | 600 | '<?xml version="1.0" ?><manifest>' |
| @@ -613,10 +613,10 @@ class SuperProjectElementTests(ManifestParseTestCase): | |||
| 613 | <superproject name="superproject" revision="refs/heads/stable" /> | 613 | <superproject name="superproject" revision="refs/heads/stable" /> |
| 614 | </manifest> | 614 | </manifest> |
| 615 | """) | 615 | """) |
| 616 | self.assertEqual(manifest.superproject['name'], 'superproject') | 616 | self.assertEqual(manifest.superproject.name, 'superproject') |
| 617 | self.assertEqual(manifest.superproject['remote'].name, 'test-remote') | 617 | self.assertEqual(manifest.superproject.remote.name, 'test-remote') |
| 618 | self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject') | 618 | self.assertEqual(manifest.superproject.remote.url, 'http://localhost/superproject') |
| 619 | self.assertEqual(manifest.superproject['revision'], 'refs/heads/stable') | 619 | self.assertEqual(manifest.superproject.revision, 'refs/heads/stable') |
| 620 | self.assertEqual( | 620 | self.assertEqual( |
| 621 | sort_attributes(manifest.ToXml().toxml()), | 621 | sort_attributes(manifest.ToXml().toxml()), |
| 622 | '<?xml version="1.0" ?><manifest>' | 622 | '<?xml version="1.0" ?><manifest>' |
| @@ -635,10 +635,10 @@ class SuperProjectElementTests(ManifestParseTestCase): | |||
| 635 | <superproject name="superproject" revision="refs/heads/stable" /> | 635 | <superproject name="superproject" revision="refs/heads/stable" /> |
| 636 | </manifest> | 636 | </manifest> |
| 637 | """) | 637 | """) |
| 638 | self.assertEqual(manifest.superproject['name'], 'superproject') | 638 | self.assertEqual(manifest.superproject.name, 'superproject') |
| 639 | self.assertEqual(manifest.superproject['remote'].name, 'test-remote') | 639 | self.assertEqual(manifest.superproject.remote.name, 'test-remote') |
| 640 | self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/superproject') | 640 | self.assertEqual(manifest.superproject.remote.url, 'http://localhost/superproject') |
| 641 | self.assertEqual(manifest.superproject['revision'], 'refs/heads/stable') | 641 | self.assertEqual(manifest.superproject.revision, 'refs/heads/stable') |
| 642 | self.assertEqual( | 642 | self.assertEqual( |
| 643 | sort_attributes(manifest.ToXml().toxml()), | 643 | sort_attributes(manifest.ToXml().toxml()), |
| 644 | '<?xml version="1.0" ?><manifest>' | 644 | '<?xml version="1.0" ?><manifest>' |
| @@ -657,10 +657,10 @@ class SuperProjectElementTests(ManifestParseTestCase): | |||
| 657 | <superproject name="platform/superproject" remote="superproject-remote"/> | 657 | <superproject name="platform/superproject" remote="superproject-remote"/> |
| 658 | </manifest> | 658 | </manifest> |
| 659 | """) | 659 | """) |
| 660 | self.assertEqual(manifest.superproject['name'], 'platform/superproject') | 660 | self.assertEqual(manifest.superproject.name, 'platform/superproject') |
| 661 | self.assertEqual(manifest.superproject['remote'].name, 'superproject-remote') | 661 | self.assertEqual(manifest.superproject.remote.name, 'superproject-remote') |
| 662 | self.assertEqual(manifest.superproject['remote'].url, 'http://localhost/platform/superproject') | 662 | self.assertEqual(manifest.superproject.remote.url, 'http://localhost/platform/superproject') |
| 663 | self.assertEqual(manifest.superproject['revision'], 'refs/heads/main') | 663 | self.assertEqual(manifest.superproject.revision, 'refs/heads/main') |
| 664 | self.assertEqual( | 664 | self.assertEqual( |
| 665 | sort_attributes(manifest.ToXml().toxml()), | 665 | sort_attributes(manifest.ToXml().toxml()), |
| 666 | '<?xml version="1.0" ?><manifest>' | 666 | '<?xml version="1.0" ?><manifest>' |
| @@ -679,9 +679,9 @@ class SuperProjectElementTests(ManifestParseTestCase): | |||
| 679 | <superproject name="superproject" remote="default-remote"/> | 679 | <superproject name="superproject" remote="default-remote"/> |
| 680 | </manifest> | 680 | </manifest> |
| 681 | """) | 681 | """) |
| 682 | self.assertEqual(manifest.superproject['name'], 'superproject') | 682 | self.assertEqual(manifest.superproject.name, 'superproject') |
| 683 | self.assertEqual(manifest.superproject['remote'].name, 'default-remote') | 683 | self.assertEqual(manifest.superproject.remote.name, 'default-remote') |
| 684 | self.assertEqual(manifest.superproject['revision'], 'refs/heads/main') | 684 | self.assertEqual(manifest.superproject.revision, 'refs/heads/main') |
| 685 | self.assertEqual( | 685 | self.assertEqual( |
| 686 | sort_attributes(manifest.ToXml().toxml()), | 686 | sort_attributes(manifest.ToXml().toxml()), |
| 687 | '<?xml version="1.0" ?><manifest>' | 687 | '<?xml version="1.0" ?><manifest>' |
