summaryrefslogtreecommitdiffstats
path: root/git_superproject.py
diff options
context:
space:
mode:
Diffstat (limited to 'git_superproject.py')
-rw-r--r--git_superproject.py51
1 files changed, 23 insertions, 28 deletions
diff --git a/git_superproject.py b/git_superproject.py
index 2a47847a..86100960 100644
--- a/git_superproject.py
+++ b/git_superproject.py
@@ -117,6 +117,11 @@ class Superproject(object):
117 branch = branch[len(R_HEADS):] 117 branch = branch[len(R_HEADS):]
118 return branch 118 return branch
119 119
120 def _LogError(self, message):
121 """Logs message to stderr and _git_event_log."""
122 print(message, file=sys.stderr)
123 self._git_event_log.ErrorEvent(message, '')
124
120 def _Init(self): 125 def _Init(self):
121 """Sets up a local Git repository to get a copy of a superproject. 126 """Sets up a local Git repository to get a copy of a superproject.
122 127
@@ -136,8 +141,8 @@ class Superproject(object):
136 capture_stderr=True) 141 capture_stderr=True)
137 retval = p.Wait() 142 retval = p.Wait()
138 if retval: 143 if retval:
139 print('repo: error: git init call failed with return code: %r, stderr: %r' % 144 self._LogError(f'repo: error: git init call failed, command: git {cmd}, '
140 (retval, p.stderr), file=sys.stderr) 145 f'return code: {retval}, stderr: {p.stderr}')
141 return False 146 return False
142 return True 147 return True
143 148
@@ -151,8 +156,7 @@ class Superproject(object):
151 True if fetch is successful, or False. 156 True if fetch is successful, or False.
152 """ 157 """
153 if not os.path.exists(self._work_git): 158 if not os.path.exists(self._work_git):
154 print('git fetch missing drectory: %s' % self._work_git, 159 self._LogError(f'git fetch missing directory: {self._work_git}')
155 file=sys.stderr)
156 return False 160 return False
157 if not git_require((2, 28, 0)): 161 if not git_require((2, 28, 0)):
158 print('superproject requires a git version 2.28 or later', file=sys.stderr) 162 print('superproject requires a git version 2.28 or later', file=sys.stderr)
@@ -167,8 +171,8 @@ class Superproject(object):
167 capture_stderr=True) 171 capture_stderr=True)
168 retval = p.Wait() 172 retval = p.Wait()
169 if retval: 173 if retval:
170 print('repo: error: git fetch call failed with return code: %r, stderr: %r' % 174 self._LogError(f'repo: error: git fetch call failed, command: git {cmd}, '
171 (retval, p.stderr), file=sys.stderr) 175 f'return code: {retval}, stderr: {p.stderr}')
172 return False 176 return False
173 return True 177 return True
174 178
@@ -181,8 +185,7 @@ class Superproject(object):
181 data: data returned from 'git ls-tree ...' instead of None. 185 data: data returned from 'git ls-tree ...' instead of None.
182 """ 186 """
183 if not os.path.exists(self._work_git): 187 if not os.path.exists(self._work_git):
184 print('git ls-tree missing drectory: %s' % self._work_git, 188 self._LogError(f'git ls-tree missing directory: {self._work_git}')
185 file=sys.stderr)
186 return None 189 return None
187 data = None 190 data = None
188 branch = 'HEAD' if not self._branch else self._branch 191 branch = 'HEAD' if not self._branch else self._branch
@@ -197,8 +200,8 @@ class Superproject(object):
197 if retval == 0: 200 if retval == 0:
198 data = p.stdout 201 data = p.stdout
199 else: 202 else:
200 print('repo: error: git ls-tree call failed with return code: %r, stderr: %r' % ( 203 self._LogError(f'repo: error: git ls-tree call failed, command: git {cmd}, '
201 retval, p.stderr), file=sys.stderr) 204 f'return code: {retval}, stderr: {p.stderr}')
202 return data 205 return data
203 206
204 def Sync(self): 207 def Sync(self):
@@ -211,17 +214,15 @@ class Superproject(object):
211 'address described in `repo version`', file=sys.stderr) 214 'address described in `repo version`', file=sys.stderr)
212 215
213 if not self._manifest.superproject: 216 if not self._manifest.superproject:
214 msg = (f'repo error: superproject tag is not defined in manifest: ' 217 self._LogError(f'repo error: superproject tag is not defined in manifest: '
215 f'{self._manifest.manifestFile}') 218 f'{self._manifest.manifestFile}')
216 print(msg, file=sys.stderr)
217 self._git_event_log.ErrorEvent(msg, '')
218 return SyncResult(False, False) 219 return SyncResult(False, False)
219 220
220 should_exit = True 221 should_exit = True
221 url = self._manifest.superproject['remote'].url 222 url = self._manifest.superproject['remote'].url
222 if not url: 223 if not url:
223 print('error: superproject URL is not defined in manifest', 224 self._LogError(f'repo error: superproject URL is not defined in manifest: '
224 file=sys.stderr) 225 f'{self._manifest.manifestFile}')
225 return SyncResult(False, should_exit) 226 return SyncResult(False, should_exit)
226 227
227 if not self._Init(): 228 if not self._Init():
@@ -244,7 +245,7 @@ class Superproject(object):
244 245
245 data = self._LsTree() 246 data = self._LsTree()
246 if not data: 247 if not data:
247 print('error: git ls-tree failed to return data for superproject', 248 print('warning: git ls-tree failed to return data for superproject',
248 file=sys.stderr) 249 file=sys.stderr)
249 return CommitIdsResult(None, True) 250 return CommitIdsResult(None, True)
250 251
@@ -271,9 +272,7 @@ class Superproject(object):
271 manifest_path: Path name of the file into which manifest is written instead of None. 272 manifest_path: Path name of the file into which manifest is written instead of None.
272 """ 273 """
273 if not os.path.exists(self._superproject_path): 274 if not os.path.exists(self._superproject_path):
274 print('error: missing superproject directory %s' % 275 self._LogError(f'error: missing superproject directory: {self._superproject_path}')
275 self._superproject_path,
276 file=sys.stderr)
277 return None 276 return None
278 manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml() 277 manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml()
279 manifest_path = self._manifest_path 278 manifest_path = self._manifest_path
@@ -281,9 +280,7 @@ class Superproject(object):
281 with open(manifest_path, 'w', encoding='utf-8') as fp: 280 with open(manifest_path, 'w', encoding='utf-8') as fp:
282 fp.write(manifest_str) 281 fp.write(manifest_str)
283 except IOError as e: 282 except IOError as e:
284 print('error: cannot write manifest to %s:\n%s' 283 self._LogError(f'error: cannot write manifest to : {manifest_path} {e}')
285 % (manifest_path, e),
286 file=sys.stderr)
287 return None 284 return None
288 return manifest_path 285 return manifest_path
289 286
@@ -319,7 +316,7 @@ class Superproject(object):
319 commit_ids_result = self._GetAllProjectsCommitIds() 316 commit_ids_result = self._GetAllProjectsCommitIds()
320 commit_ids = commit_ids_result.commit_ids 317 commit_ids = commit_ids_result.commit_ids
321 if not commit_ids: 318 if not commit_ids:
322 print('error: Cannot get project commit ids from manifest', file=sys.stderr) 319 print('warning: Cannot get project commit ids from manifest', file=sys.stderr)
323 return UpdateProjectsResult(None, commit_ids_result.fatal) 320 return UpdateProjectsResult(None, commit_ids_result.fatal)
324 321
325 projects_missing_commit_ids = [] 322 projects_missing_commit_ids = []
@@ -334,10 +331,8 @@ class Superproject(object):
334 # If superproject doesn't have a commit id for a project, then report an 331 # If superproject doesn't have a commit id for a project, then report an
335 # error event and continue as if do not use superproject is specified. 332 # error event and continue as if do not use superproject is specified.
336 if projects_missing_commit_ids: 333 if projects_missing_commit_ids:
337 msg = (f'error: please file a bug using {self._manifest.contactinfo.bugurl} ' 334 self._LogError(f'error: please file a bug using {self._manifest.contactinfo.bugurl} '
338 f'to report missing commit_ids for: {projects_missing_commit_ids}') 335 f'to report missing commit_ids for: {projects_missing_commit_ids}')
339 print(msg, file=sys.stderr)
340 self._git_event_log.ErrorEvent(msg, '')
341 return UpdateProjectsResult(None, False) 336 return UpdateProjectsResult(None, False)
342 337
343 for project in projects: 338 for project in projects: