diff options
| -rw-r--r-- | git_config.py | 14 | ||||
| -rw-r--r-- | project.py | 2 | ||||
| -rw-r--r-- | tests/test_project.py | 79 |
3 files changed, 90 insertions, 5 deletions
diff --git a/git_config.py b/git_config.py index 94378e9a..af1a1015 100644 --- a/git_config.py +++ b/git_config.py | |||
| @@ -22,6 +22,7 @@ import re | |||
| 22 | import ssl | 22 | import ssl |
| 23 | import subprocess | 23 | import subprocess |
| 24 | import sys | 24 | import sys |
| 25 | from typing import Union | ||
| 25 | import urllib.error | 26 | import urllib.error |
| 26 | import urllib.request | 27 | import urllib.request |
| 27 | 28 | ||
| @@ -117,7 +118,7 @@ class GitConfig(object): | |||
| 117 | return self.defaults.Has(name, include_defaults=True) | 118 | return self.defaults.Has(name, include_defaults=True) |
| 118 | return False | 119 | return False |
| 119 | 120 | ||
| 120 | def GetInt(self, name): | 121 | def GetInt(self, name: str) -> Union[int, None]: |
| 121 | """Returns an integer from the configuration file. | 122 | """Returns an integer from the configuration file. |
| 122 | 123 | ||
| 123 | This follows the git config syntax. | 124 | This follows the git config syntax. |
| @@ -126,7 +127,7 @@ class GitConfig(object): | |||
| 126 | name: The key to lookup. | 127 | name: The key to lookup. |
| 127 | 128 | ||
| 128 | Returns: | 129 | Returns: |
| 129 | None if the value was not defined, or is not a boolean. | 130 | None if the value was not defined, or is not an int. |
| 130 | Otherwise, the number itself. | 131 | Otherwise, the number itself. |
| 131 | """ | 132 | """ |
| 132 | v = self.GetString(name) | 133 | v = self.GetString(name) |
| @@ -152,6 +153,9 @@ class GitConfig(object): | |||
| 152 | try: | 153 | try: |
| 153 | return int(v, base=base) * mult | 154 | return int(v, base=base) * mult |
| 154 | except ValueError: | 155 | except ValueError: |
| 156 | print( | ||
| 157 | f"warning: expected {name} to represent an integer, got {v} instead", | ||
| 158 | file=sys.stderr) | ||
| 155 | return None | 159 | return None |
| 156 | 160 | ||
| 157 | def DumpConfigDict(self): | 161 | def DumpConfigDict(self): |
| @@ -169,7 +173,7 @@ class GitConfig(object): | |||
| 169 | config_dict[key] = self.GetString(key) | 173 | config_dict[key] = self.GetString(key) |
| 170 | return config_dict | 174 | return config_dict |
| 171 | 175 | ||
| 172 | def GetBoolean(self, name): | 176 | def GetBoolean(self, name: str) -> Union[str, None]: |
| 173 | """Returns a boolean from the configuration file. | 177 | """Returns a boolean from the configuration file. |
| 174 | None : The value was not defined, or is not a boolean. | 178 | None : The value was not defined, or is not a boolean. |
| 175 | True : The value was set to true or yes. | 179 | True : The value was set to true or yes. |
| @@ -183,6 +187,8 @@ class GitConfig(object): | |||
| 183 | return True | 187 | return True |
| 184 | if v in ('false', 'no'): | 188 | if v in ('false', 'no'): |
| 185 | return False | 189 | return False |
| 190 | print(f"warning: expected {name} to represent a boolean, got {v} instead", | ||
| 191 | file=sys.stderr) | ||
| 186 | return None | 192 | return None |
| 187 | 193 | ||
| 188 | def SetBoolean(self, name, value): | 194 | def SetBoolean(self, name, value): |
| @@ -191,7 +197,7 @@ class GitConfig(object): | |||
| 191 | value = 'true' if value else 'false' | 197 | value = 'true' if value else 'false' |
| 192 | self.SetString(name, value) | 198 | self.SetString(name, value) |
| 193 | 199 | ||
| 194 | def GetString(self, name, all_keys=False): | 200 | def GetString(self, name: str, all_keys: bool = False) -> Union[str, None]: |
| 195 | """Get the first value for a key, or None if it is not defined. | 201 | """Get the first value for a key, or None if it is not defined. |
| 196 | 202 | ||
| 197 | This configuration file is used first, if the key is not | 203 | This configuration file is used first, if the key is not |
| @@ -3505,7 +3505,7 @@ class ManifestProject(MetaProject): | |||
| 3505 | @property | 3505 | @property |
| 3506 | def partial_clone_exclude(self): | 3506 | def partial_clone_exclude(self): |
| 3507 | """Partial clone exclude string""" | 3507 | """Partial clone exclude string""" |
| 3508 | return self.config.GetBoolean('repo.partialcloneexclude') | 3508 | return self.config.GetString('repo.partialcloneexclude') |
| 3509 | 3509 | ||
| 3510 | @property | 3510 | @property |
| 3511 | def manifest_platform(self): | 3511 | def manifest_platform(self): |
diff --git a/tests/test_project.py b/tests/test_project.py index 47018d1c..7d07b705 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -22,6 +22,7 @@ import tempfile | |||
| 22 | import unittest | 22 | import unittest |
| 23 | 23 | ||
| 24 | import error | 24 | import error |
| 25 | import manifest_xml | ||
| 25 | import git_command | 26 | import git_command |
| 26 | import git_config | 27 | import git_config |
| 27 | import platform_utils | 28 | import platform_utils |
| @@ -411,3 +412,81 @@ class MigrateWorkTreeTests(unittest.TestCase): | |||
| 411 | self.assertTrue((dotgit / name).is_file()) | 412 | self.assertTrue((dotgit / name).is_file()) |
| 412 | for name in self._SYMLINKS: | 413 | for name in self._SYMLINKS: |
| 413 | self.assertTrue((dotgit / name).is_symlink()) | 414 | self.assertTrue((dotgit / name).is_symlink()) |
| 415 | |||
| 416 | |||
| 417 | class ManifestPropertiesFetchedCorrectly(unittest.TestCase): | ||
| 418 | """Ensure properties are fetched properly.""" | ||
| 419 | |||
| 420 | def setUpManifest(self, tempdir): | ||
| 421 | repo_trace._TRACE_FILE = os.path.join(tempdir, 'TRACE_FILE_from_test') | ||
| 422 | |||
| 423 | repodir = os.path.join(tempdir, '.repo') | ||
| 424 | manifest_dir = os.path.join(repodir, 'manifests') | ||
| 425 | manifest_file = os.path.join( | ||
| 426 | repodir, manifest_xml.MANIFEST_FILE_NAME) | ||
| 427 | local_manifest_dir = os.path.join( | ||
| 428 | repodir, manifest_xml.LOCAL_MANIFESTS_DIR_NAME) | ||
| 429 | os.mkdir(repodir) | ||
| 430 | os.mkdir(manifest_dir) | ||
| 431 | manifest = manifest_xml.XmlManifest(repodir, manifest_file) | ||
| 432 | |||
| 433 | return project.ManifestProject( | ||
| 434 | manifest, 'test/manifest', os.path.join(tempdir, '.git'), tempdir) | ||
| 435 | |||
| 436 | def test_manifest_config_properties(self): | ||
| 437 | """Test we are fetching the manifest config properties correctly.""" | ||
| 438 | |||
| 439 | with TempGitTree() as tempdir: | ||
| 440 | fakeproj = self.setUpManifest(tempdir) | ||
| 441 | |||
| 442 | # Set property using the expected Set method, then ensure | ||
| 443 | # the porperty functions are using the correct Get methods. | ||
| 444 | fakeproj.config.SetString( | ||
| 445 | 'manifest.standalone', 'https://chicken/manifest.git') | ||
| 446 | self.assertEqual( | ||
| 447 | fakeproj.standalone_manifest_url, 'https://chicken/manifest.git') | ||
| 448 | |||
| 449 | fakeproj.config.SetString('manifest.groups', 'test-group, admin-group') | ||
| 450 | self.assertEqual(fakeproj.manifest_groups, 'test-group, admin-group') | ||
| 451 | |||
| 452 | fakeproj.config.SetString('repo.reference', 'mirror/ref') | ||
| 453 | self.assertEqual(fakeproj.reference, 'mirror/ref') | ||
| 454 | |||
| 455 | fakeproj.config.SetBoolean('repo.dissociate', False) | ||
| 456 | self.assertFalse(fakeproj.dissociate) | ||
| 457 | |||
| 458 | fakeproj.config.SetBoolean('repo.archive', False) | ||
| 459 | self.assertFalse(fakeproj.archive) | ||
| 460 | |||
| 461 | fakeproj.config.SetBoolean('repo.mirror', False) | ||
| 462 | self.assertFalse(fakeproj.mirror) | ||
| 463 | |||
| 464 | fakeproj.config.SetBoolean('repo.worktree', False) | ||
| 465 | self.assertFalse(fakeproj.use_worktree) | ||
| 466 | |||
| 467 | fakeproj.config.SetBoolean('repo.clonebundle', False) | ||
| 468 | self.assertFalse(fakeproj.clone_bundle) | ||
| 469 | |||
| 470 | fakeproj.config.SetBoolean('repo.submodules', False) | ||
| 471 | self.assertFalse(fakeproj.submodules) | ||
| 472 | |||
| 473 | fakeproj.config.SetBoolean('repo.git-lfs', False) | ||
| 474 | self.assertFalse(fakeproj.git_lfs) | ||
| 475 | |||
| 476 | fakeproj.config.SetBoolean('repo.superproject', False) | ||
| 477 | self.assertFalse(fakeproj.use_superproject) | ||
| 478 | |||
| 479 | fakeproj.config.SetBoolean('repo.partialclone', False) | ||
| 480 | self.assertFalse(fakeproj.partial_clone) | ||
| 481 | |||
| 482 | fakeproj.config.SetString('repo.depth', '48') | ||
| 483 | self.assertEquals(fakeproj.depth, '48') | ||
| 484 | |||
| 485 | fakeproj.config.SetString('repo.clonefilter', 'blob:limit=10M') | ||
| 486 | self.assertEquals(fakeproj.clone_filter, 'blob:limit=10M') | ||
| 487 | |||
| 488 | fakeproj.config.SetString('repo.partialcloneexclude', 'third_party/big_repo') | ||
| 489 | self.assertEquals(fakeproj.partial_clone_exclude, 'third_party/big_repo') | ||
| 490 | |||
| 491 | fakeproj.config.SetString('manifest.platform', 'auto') | ||
| 492 | self.assertEquals(fakeproj.manifest_platform, 'auto') | ||
