summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaman Tenneti <rtenneti@google.com>2021-07-06 21:30:06 -0700
committerRaman Tenneti <rtenneti@google.com>2021-07-14 00:41:36 +0000
commit8db30d686a5298a28c6275cc05fb24fb1cfa1ba5 (patch)
treef6bbed3e2467e5c462daad49eb62b437780615b4
parente39d8b36f6bee37424712a9b6ba7765183175c5e (diff)
downloadgit-repo-8db30d686a5298a28c6275cc05fb24fb1cfa1ba5.tar.gz
superproject - More friendly user message when superproject failed.v2.16.1
superproject is going to be default for some users. This change doesn't fail for repo init or repo sync if source couldn't be synced because of errors in superproject and superproject=true in the config file. The commands will fail if --use-superproject is specified on the command line explicitly. The error messages are logged with trace2 event logs and will be monitored. + sync - When there are errors with superproject and git_superproject says it is fatal failure, sync will exit only when --use-superproject option is specified on the command line. + init - command doesn't fail *if there are any superproject errors), but it will print a warning message and logs message via trace2 event logs. For fatal errors, init will exit only when --use-superproject option is specified on the command line. + All git commands log the command that is being executed so trace2 event logs will know the manifest, remote url and the branch name. There is no functional change other than fatal errors are honored with --use-supeproject option with init/sync commands. Tested the code with the following commands. $ ./run_tests -v Test 1 - sync'ing without errors -------------------------------- Added the following lines to '~/.repoconfig/config [repo] superproject = true $ repo_dev init -u https://android.googlesource.com/platform/manifest -b android-s-beta-2 NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` repo: error: git fetch call failed, command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2 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 Your identity is: Raman Tenneti <rtenneti@google.com> If you want to change this, please re-run 'repo init' with --config-name repo has been initialized in /usr/local/google/home/rtenneti/work/drive2/android/test $ repo_dev sync remote: Total 4 (delta 1), reused 4 (delta 1) NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` /usr/local/google/home/rtenneti/work/drive2/android/aosp/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Initial setup for superproject completed. ... Test 2 - init and sync fail when --use-superproject option is passed -------------------------------------------------------------------- $ repo_dev init -u https://android.googlesource.com/platform/manifest -b android-s-beta-2 --use-superproject remote: Total 57 (delta 16), reused 56 (delta 16) NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` repo: error: git fetch call failed, command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2 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 rtenneti@rtenneti2:~/work/drive2/android/test$ repo_dev sync --use-superproject NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` repo: error: git fetch call failed, command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2 warning: Cannot get project commit ids from manifest 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. Test 3 - git fetch command fails and git command is printed ----------------------------------------------------------- With config change $ repo_dev init -u https://android.googlesource.com/platform/manifest -b android-s-beta-2 ... NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` .../android/test/.repo/exp-superproject/925043f706ba64db713e9bf3b55987e2-superproject.git: Performing initial setup for superproject; this might take several minutes. repo: error: git fetch call failed,command: git ['fetch', 'https://android.googlesource.com/platform/superproject', '--depth', '1', '--force', '--no-tags', '--filter', 'blob:none', 'android-s-beta-2:android-s-beta-2'], return code: 128, stderr: fatal: couldn't find remote ref android-s-beta-2 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 avoid the repo warning Your identity is: Raman Tenneti <rtenneti@google.com> If you want to change this, please re-run 'repo init' with --config-name repo has been initialized in .... Test 4 - no superproject tag ----------------------------- $ repo_dev init -u https://android.googlesource.com/platform/manifest -b pie-dev ... NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` repo error: superproject tag is not defined in manifest: .../android/pie_dev/.repo/manifest.xml 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 avoid the repo warning Your identity is: Raman Tenneti <rtenneti@google.com> If you want to change this, please re-run 'repo init' with --config-name repo has been initialized in ... $ repo_dev sync NOTICE: --use-superproject is in beta; report any issues to the address described in `repo version` repo error: superproject tag is not defined in manifest: /usr/local/google/home/rtenneti/work/drive2/android/pie_dev/.repo/manifest.xml warning: Cannot get project commit ids from manifest warning: Update of revsionId from superproject has failed. Please resync with --no-use-superproject option to avoid the repo warning. Bug: [google internal] b/192614798 Bug: [google internal] b/Bug: [google internal] b/192614798 Change-Id: I9a97a0e7d9e609fad151bd7dd9cfc523eaa887cd Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/311502 Reviewed-by: Amith Dsouza <amithds@google.com> Reviewed-by: Xin Li <delphij@google.com> Tested-by: Raman Tenneti <rtenneti@google.com>
-rw-r--r--git_superproject.py51
-rw-r--r--subcmds/init.py8
-rw-r--r--subcmds/sync.py7
3 files changed, 33 insertions, 33 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:
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.
100 quiet=opt.quiet) 100 quiet=opt.quiet)
101 sync_result = superproject.Sync() 101 sync_result = superproject.Sync()
102 if not sync_result.success: 102 if not sync_result.success:
103 print('error: git update of superproject failed', file=sys.stderr) 103 print('warning: git update of superproject failed, repo sync will not '
104 if sync_result.fatal: 104 'use superproject to fetch source; while this error is not fatal, '
105 'and you can continue to run repo sync, please run repo init with '
106 'the --no-use-superproject option to stop seeing this warning',
107 file=sys.stderr)
108 if sync_result.fatal and opt.use_superproject is not None:
105 sys.exit(1) 109 sys.exit(1)
106 110
107 def _SyncManifest(self, opt): 111 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.
309 if manifest_path: 309 if manifest_path:
310 self._ReloadManifest(manifest_path, load_local_manifests) 310 self._ReloadManifest(manifest_path, load_local_manifests)
311 else: 311 else:
312 print('error: Update of revsionId from superproject has failed. ' 312 print('warning: Update of revisionId from superproject has failed, '
313 'Please resync with --no-use-superproject option', 313 'repo sync will not use superproject to fetch the source. ',
314 'Please resync with the --no-use-superproject option to avoid this repo warning.',
314 file=sys.stderr) 315 file=sys.stderr)
315 if update_result.fatal: 316 if update_result.fatal and opt.use_superproject is not None:
316 sys.exit(1) 317 sys.exit(1)
317 return manifest_path 318 return manifest_path
318 319