diff options
author | Dan Albert <danalbert@google.com> | 2024-03-07 23:14:33 +0000 |
---|---|---|
committer | Dan Albert <danalbert@google.com> | 2024-03-08 00:01:58 +0000 |
commit | f70d40ae76f8f1362461f2dae47a8b5545056699 (patch) | |
tree | d0f4f81069f2c0e7f40c96ceafbd23f66060bb11 | |
parent | b9245d9d80977de0d9f00ad8c57ab96bb7282dec (diff) | |
download | external_updater-f70d40ae76f8f1362461f2dae47a8b5545056699.tar.gz |
Avoid tag recommendation if repo has no tags.
get_latest_stable_release_tag raises ValueError when passed an empty
list. In this case we should be returning None to signify that there
is no latest tag.
This was caught by tests/endtoend/test_check.py, but those can't be
run in CI because we can't run repo in CI, so we can't set up the test
directories. For the same reason it's rather difficult to set up a
unit test to cover this, since GitUpdater.latest_tag_of_upstream
assumes that it has a git repo that's been set up with the
update_origin remote. With some effort that could probably be hacked
around, but it's beyond the scope of this fix.
Bug: None
Test: make test
Change-Id: I817f46543a38777b109a22f2064580061598ead2
-rw-r--r-- | git_updater.py | 3 | ||||
-rw-r--r-- | test_updater_utils.py | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/git_updater.py b/git_updater.py index dbcb9b2..2035201 100644 --- a/git_updater.py +++ b/git_updater.py @@ -119,6 +119,9 @@ class GitUpdater(base_updater.Updater): def latest_tag_of_upstream(self) -> str | None: tags = git_utils.list_remote_tags(self._proj_path, self.UPSTREAM_REMOTE_NAME) + if not tags: + return None + parsed_tags = [updater_utils.parse_remote_tag(tag) for tag in tags] tag = updater_utils.get_latest_stable_release_tag(self._old_identifier.version, parsed_tags) return tag diff --git a/test_updater_utils.py b/test_updater_utils.py index 632ba9a..08d6889 100644 --- a/test_updater_utils.py +++ b/test_updater_utils.py @@ -73,6 +73,11 @@ class GetLatestVersionTest(unittest.TestCase): self.assertEqual( updater_utils.get_latest_stable_release_tag("r26", ["r26", "r26b"]), "r26b") + def test_no_tags(self) -> None: + """Tests that an error is raised when there are no tags.""" + with self.assertRaises(ValueError): + updater_utils.get_latest_stable_release_tag("v1.0.0", []) + if __name__ == "__main__": unittest.main(verbosity=2) |