Handle failed match case for finding tags.
mypy flags the original code because a failed match() would return
None, and this would raise AttributeError when calling .group().
Appease mypy by improving the error message.
Bug: None
Test: mypy .
Change-Id: I6a9536586529d687608a7edaf4d1dca3717ed339
diff --git a/git_utils.py b/git_utils.py
index 5fc9acf..b84498e 100644
--- a/git_utils.py
+++ b/git_utils.py
@@ -126,7 +126,9 @@
"""Lists all tags for a remote."""
regex = re.compile(r".*refs/tags/(?P<tag>[^\^]*).*")
def parse_remote_tag(line: str) -> str:
- return regex.match(line).group("tag")
+ if (m := regex.match(line)) is not None:
+ return m.group("tag")
+ raise ValueError(f"Could not parse tag from {line}")
lines = _run(['git', "ls-remote", "--tags", remote_name],
cwd=proj_path).splitlines()