[Updater] Support git tag
If the upstream is GIT and version is not a hash, updater will try to
list upstream tags to find a newer version. And suggest to merge from
that tag.
Change-Id: I34651815c761c78fd0485df0a84adc086a810e9e
Test: Change googletest/METADATA to follow upstream releases. And run updater.
diff --git a/git_utils.py b/git_utils.py
index b2f6bbb..abfcea7 100644
--- a/git_utils.py
+++ b/git_utils.py
@@ -14,6 +14,7 @@
'''Helper functions to communicate with Git.'''
import datetime
+import re
import subprocess
@@ -81,3 +82,33 @@
remote_path_len = len(remote_path)
return [line[remote_path_len:] for line in stripped
if line.startswith(remote_path)]
+
+
+def _parse_remote_tag(line):
+ tag_prefix = 'refs/tags/'
+ tag_suffix = '^{}'
+ try:
+ line = line[line.index(tag_prefix):]
+ except ValueError:
+ return None
+ line = line[len(tag_prefix):]
+ if line.endswith(tag_suffix):
+ line = line[:-len(tag_suffix)]
+ return line
+
+
+def list_remote_tags(proj_path, remote_name):
+ """Lists all tags for a remote."""
+ out = _run(['git', "ls-remote", "--tags", remote_name],
+ cwd=proj_path)
+ lines = out.stdout.decode('utf-8').splitlines()
+ tags = [_parse_remote_tag(line) for line in lines]
+ return list(set(tags))
+
+
+COMMIT_PATTERN = r'^[a-f0-9]{40}$'
+COMMIT_RE = re.compile(COMMIT_PATTERN)
+
+
+def is_commit(commit):
+ return bool(COMMIT_RE.match(commit))