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): branch = branch[len(R_HEADS):] return branch + def _LogError(self, message): + """Logs message to stderr and _git_event_log.""" + print(message, file=sys.stderr) + self._git_event_log.ErrorEvent(message, '') + def _Init(self): """Sets up a local Git repository to get a copy of a superproject. @@ -136,8 +141,8 @@ class Superproject(object): capture_stderr=True) retval = p.Wait() if retval: - print('repo: error: git init call failed with return code: %r, stderr: %r' % - (retval, p.stderr), file=sys.stderr) + self._LogError(f'repo: error: git init call failed, command: git {cmd}, ' + f'return code: {retval}, stderr: {p.stderr}') return False return True @@ -151,8 +156,7 @@ class Superproject(object): True if fetch is successful, or False. """ if not os.path.exists(self._work_git): - print('git fetch missing drectory: %s' % self._work_git, - file=sys.stderr) + self._LogError(f'git fetch missing directory: {self._work_git}') return False if not git_require((2, 28, 0)): print('superproject requires a git version 2.28 or later', file=sys.stderr) @@ -167,8 +171,8 @@ class Superproject(object): capture_stderr=True) retval = p.Wait() if retval: - print('repo: error: git fetch call failed with return code: %r, stderr: %r' % - (retval, p.stderr), file=sys.stderr) + self._LogError(f'repo: error: git fetch call failed, command: git {cmd}, ' + f'return code: {retval}, stderr: {p.stderr}') return False return True @@ -181,8 +185,7 @@ class Superproject(object): data: data returned from 'git ls-tree ...' instead of None. """ if not os.path.exists(self._work_git): - print('git ls-tree missing drectory: %s' % self._work_git, - file=sys.stderr) + self._LogError(f'git ls-tree missing directory: {self._work_git}') return None data = None branch = 'HEAD' if not self._branch else self._branch @@ -197,8 +200,8 @@ class Superproject(object): if retval == 0: data = p.stdout else: - print('repo: error: git ls-tree call failed with return code: %r, stderr: %r' % ( - retval, p.stderr), file=sys.stderr) + self._LogError(f'repo: error: git ls-tree call failed, command: git {cmd}, ' + f'return code: {retval}, stderr: {p.stderr}') return data def Sync(self): @@ -211,17 +214,15 @@ class Superproject(object): 'address described in `repo version`', file=sys.stderr) if not self._manifest.superproject: - msg = (f'repo error: superproject tag is not defined in manifest: ' - f'{self._manifest.manifestFile}') - print(msg, file=sys.stderr) - self._git_event_log.ErrorEvent(msg, '') + self._LogError(f'repo error: superproject tag is not defined in manifest: ' + f'{self._manifest.manifestFile}') return SyncResult(False, False) should_exit = True url = self._manifest.superproject['remote'].url if not url: - print('error: superproject URL is not defined in manifest', - file=sys.stderr) + self._LogError(f'repo error: superproject URL is not defined in manifest: ' + f'{self._manifest.manifestFile}') return SyncResult(False, should_exit) if not self._Init(): @@ -244,7 +245,7 @@ class Superproject(object): data = self._LsTree() if not data: - print('error: git ls-tree failed to return data for superproject', + print('warning: git ls-tree failed to return data for superproject', file=sys.stderr) return CommitIdsResult(None, True) @@ -271,9 +272,7 @@ class Superproject(object): manifest_path: Path name of the file into which manifest is written instead of None. """ if not os.path.exists(self._superproject_path): - print('error: missing superproject directory %s' % - self._superproject_path, - file=sys.stderr) + self._LogError(f'error: missing superproject directory: {self._superproject_path}') return None manifest_str = self._manifest.ToXml(groups=self._manifest.GetGroupsStr()).toxml() manifest_path = self._manifest_path @@ -281,9 +280,7 @@ class Superproject(object): with open(manifest_path, 'w', encoding='utf-8') as fp: fp.write(manifest_str) except IOError as e: - print('error: cannot write manifest to %s:\n%s' - % (manifest_path, e), - file=sys.stderr) + self._LogError(f'error: cannot write manifest to : {manifest_path} {e}') return None return manifest_path @@ -319,7 +316,7 @@ class Superproject(object): commit_ids_result = self._GetAllProjectsCommitIds() commit_ids = commit_ids_result.commit_ids if not commit_ids: - print('error: Cannot get project commit ids from manifest', file=sys.stderr) + print('warning: Cannot get project commit ids from manifest', file=sys.stderr) return UpdateProjectsResult(None, commit_ids_result.fatal) projects_missing_commit_ids = [] @@ -334,10 +331,8 @@ class Superproject(object): # If superproject doesn't have a commit id for a project, then report an # error event and continue as if do not use superproject is specified. if projects_missing_commit_ids: - msg = (f'error: please file a bug using {self._manifest.contactinfo.bugurl} ' - f'to report missing commit_ids for: {projects_missing_commit_ids}') - print(msg, file=sys.stderr) - self._git_event_log.ErrorEvent(msg, '') + self._LogError(f'error: please file a bug using {self._manifest.contactinfo.bugurl} ' + f'to report missing commit_ids for: {projects_missing_commit_ids}') return UpdateProjectsResult(None, False) for project in projects: diff --git a/subcmds/init.py b/subcmds/init.py index 536e367c..5671fc24 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -100,8 +100,12 @@ to update the working directory files. quiet=opt.quiet) sync_result = superproject.Sync() if not sync_result.success: - print('error: git update of superproject failed', file=sys.stderr) - if sync_result.fatal: + print('warning: git update of superproject failed, repo sync will not ' + 'use superproject to fetch source; while this error is not fatal, ' + 'and you can continue to run repo sync, please run repo init with ' + 'the --no-use-superproject option to stop seeing this warning', + file=sys.stderr) + if sync_result.fatal and opt.use_superproject is not None: sys.exit(1) def _SyncManifest(self, opt): diff --git a/subcmds/sync.py b/subcmds/sync.py index bd5ffd0c..e6dbf1c8 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -309,10 +309,11 @@ later is required to fix a server side protocol bug. if manifest_path: self._ReloadManifest(manifest_path, load_local_manifests) else: - print('error: Update of revsionId from superproject has failed. ' - 'Please resync with --no-use-superproject option', + print('warning: Update of revisionId from superproject has failed, ' + 'repo sync will not use superproject to fetch the source. ', + 'Please resync with the --no-use-superproject option to avoid this repo warning.', file=sys.stderr) - if update_result.fatal: + if update_result.fatal and opt.use_superproject is not None: sys.exit(1) return manifest_path