@@ -246,9 +246,25 @@ func (sg *sourceGateway) exportVersionTo(ctx context.Context, v Version, to stri
246
246
return err
247
247
}
248
248
249
- return sg .suprvsr .do (ctx , sg .src .upstreamURL (), ctExportTree , func (ctx context.Context ) error {
249
+ err = sg .suprvsr .do (ctx , sg .src .upstreamURL (), ctExportTree , func (ctx context.Context ) error {
250
250
return sg .src .exportRevisionTo (ctx , r , to )
251
251
})
252
+
253
+ // It's possible (in git) that we may have tried this against a version that
254
+ // doesn't exist in the repository cache, even though we know it exists in
255
+ // the upstream. If it looks like that might be the case, update the local
256
+ // and retry.
257
+ // TODO(sdboyer) It'd be better if we could check the error to see if this
258
+ // actually was the cause of the problem.
259
+ if err != nil && sg .srcState & sourceHasLatestLocally == 0 {
260
+ if _ , err = sg .require (ctx , sourceHasLatestLocally ); err != nil {
261
+ err = sg .suprvsr .do (ctx , sg .src .upstreamURL (), ctExportTree , func (ctx context.Context ) error {
262
+ return sg .src .exportRevisionTo (ctx , r , to )
263
+ })
264
+ }
265
+ }
266
+
267
+ return err
252
268
}
253
269
254
270
func (sg * sourceGateway ) getManifestAndLock (ctx context.Context , pr ProjectRoot , v Version , an ProjectAnalyzer ) (Manifest , Lock , error ) {
@@ -276,6 +292,27 @@ func (sg *sourceGateway) getManifestAndLock(ctx context.Context, pr ProjectRoot,
276
292
m , l , err = sg .src .getManifestAndLock (ctx , pr , r , an )
277
293
return err
278
294
})
295
+
296
+ // It's possible (in git) that we may have tried this against a version that
297
+ // doesn't exist in the repository cache, even though we know it exists in
298
+ // the upstream. If it looks like that might be the case, update the local
299
+ // and retry.
300
+ // TODO(sdboyer) It'd be better if we could check the error to see if this
301
+ // actually was the cause of the problem.
302
+ if err != nil && sg .srcState & sourceHasLatestLocally == 0 {
303
+ // TODO(sdboyer) we should warn/log/something in adaptive recovery
304
+ // situations like this
305
+ _ , err = sg .require (ctx , sourceHasLatestLocally )
306
+ if err != nil {
307
+ return nil , nil , err
308
+ }
309
+
310
+ err = sg .suprvsr .do (ctx , label , ctGetManifestAndLock , func (ctx context.Context ) error {
311
+ m , l , err = sg .src .getManifestAndLock (ctx , pr , r , an )
312
+ return err
313
+ })
314
+ }
315
+
279
316
if err != nil {
280
317
return nil , nil , err
281
318
}
@@ -310,6 +347,27 @@ func (sg *sourceGateway) listPackages(ctx context.Context, pr ProjectRoot, v Ver
310
347
ptree , err = sg .src .listPackages (ctx , pr , r )
311
348
return err
312
349
})
350
+
351
+ // It's possible (in git) that we may have tried this against a version that
352
+ // doesn't exist in the repository cache, even though we know it exists in
353
+ // the upstream. If it looks like that might be the case, update the local
354
+ // and retry.
355
+ // TODO(sdboyer) It'd be better if we could check the error to see if this
356
+ // actually was the cause of the problem.
357
+ if err != nil && sg .srcState & sourceHasLatestLocally == 0 {
358
+ // TODO(sdboyer) we should warn/log/something in adaptive recovery
359
+ // situations like this
360
+ _ , err = sg .require (ctx , sourceHasLatestLocally )
361
+ if err != nil {
362
+ return pkgtree.PackageTree {}, err
363
+ }
364
+
365
+ err = sg .suprvsr .do (ctx , label , ctGetManifestAndLock , func (ctx context.Context ) error {
366
+ ptree , err = sg .src .listPackages (ctx , pr , r )
367
+ return err
368
+ })
369
+ }
370
+
313
371
if err != nil {
314
372
return pkgtree.PackageTree {}, err
315
373
}
0 commit comments