summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/utils/gitarchive.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/utils/gitarchive.py')
-rw-r--r--meta/lib/oeqa/utils/gitarchive.py36
1 files changed, 32 insertions, 4 deletions
diff --git a/meta/lib/oeqa/utils/gitarchive.py b/meta/lib/oeqa/utils/gitarchive.py
index 6e8040eb5c..1a28a09efe 100644
--- a/meta/lib/oeqa/utils/gitarchive.py
+++ b/meta/lib/oeqa/utils/gitarchive.py
@@ -100,9 +100,36 @@ def git_commit_data(repo, data_dir, branch, message, exclude, notes, log):
100 if os.path.exists(tmp_index): 100 if os.path.exists(tmp_index):
101 os.unlink(tmp_index) 101 os.unlink(tmp_index)
102 102
103def get_tags(repo, pattern=None, url=None):
104 """ Fetch remote tags from current repository
105
106 A pattern can be provided to filter returned tags list
107 An URL can be provided if local repository has no valid remote configured
108 """
109
110 base_cmd = ['ls-remote', '--refs', '--tags', '-q']
111 cmd = base_cmd.copy()
112
113 # First try to fetch tags from repository configured remote
114 cmd.append('origin')
115 if pattern:
116 cmd.append(pattern)
117 try:
118 tags_refs = repo.run_cmd(cmd)
119 except GitError as e:
120 # If it fails, retry with repository url if one is provided
121 if not url:
122 raise(e)
123 cmd = base_cmd.copy()
124 cmd.append(url)
125 if pattern:
126 cmd.append(pattern)
127 tags_refs = repo.run_cmd(cmd)
128
129 return ["".join(d.split()[1].split('/', 2)[2:]) for d in tags_refs.splitlines()]
103 130
104def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern, 131def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern,
105 keywords): 132 url, keywords):
106 """Generate tag name and message, with support for running id number""" 133 """Generate tag name and message, with support for running id number"""
107 keyws = keywords.copy() 134 keyws = keywords.copy()
108 # Tag number is handled specially: if not defined, we autoincrement it 135 # Tag number is handled specially: if not defined, we autoincrement it
@@ -116,7 +143,7 @@ def expand_tag_strings(repo, name_pattern, msg_subj_pattern, msg_body_pattern,
116 tag_re = tag_re.format(tag_number='(?P<tag_number>[0-9]{1,5})') 143 tag_re = tag_re.format(tag_number='(?P<tag_number>[0-9]{1,5})')
117 144
118 keyws['tag_number'] = 0 145 keyws['tag_number'] = 0
119 for existing_tag in repo.run_cmd('tag').splitlines(): 146 for existing_tag in get_tags(repo, url=url):
120 match = re.match(tag_re, existing_tag) 147 match = re.match(tag_re, existing_tag)
121 148
122 if match and int(match.group('tag_number')) >= keyws['tag_number']: 149 if match and int(match.group('tag_number')) >= keyws['tag_number']:
@@ -143,7 +170,8 @@ def gitarchive(data_dir, git_dir, no_create, bare, commit_msg_subject, commit_ms
143 if not no_tag and tagname: 170 if not no_tag and tagname:
144 tag_name, tag_msg = expand_tag_strings(data_repo, tagname, 171 tag_name, tag_msg = expand_tag_strings(data_repo, tagname,
145 tag_msg_subject, 172 tag_msg_subject,
146 tag_msg_body, keywords) 173 tag_msg_body,
174 push, keywords)
147 175
148 # Commit data 176 # Commit data
149 commit = git_commit_data(data_repo, data_dir, branch_name, 177 commit = git_commit_data(data_repo, data_dir, branch_name,
@@ -181,7 +209,7 @@ def get_test_runs(log, repo, tag_name, **kwargs):
181 209
182 # Get a list of all matching tags 210 # Get a list of all matching tags
183 tag_pattern = tag_name.format(**str_fields) 211 tag_pattern = tag_name.format(**str_fields)
184 tags = repo.run_cmd(['tag', '-l', tag_pattern]).splitlines() 212 tags = get_tags(repo, pattern=tag_pattern)
185 log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern) 213 log.debug("Found %d tags matching pattern '%s'", len(tags), tag_pattern)
186 214
187 # Parse undefined fields from tag names 215 # Parse undefined fields from tag names