Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

Commit 4871d2f

Browse files
committed
Guard against possibly stale local git repos
1 parent 1c168c0 commit 4871d2f

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

internal/gps/source.go

+59-1
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,25 @@ func (sg *sourceGateway) exportVersionTo(ctx context.Context, v Version, to stri
246246
return err
247247
}
248248

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 {
250250
return sg.src.exportRevisionTo(ctx, r, to)
251251
})
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
252268
}
253269

254270
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,
276292
m, l, err = sg.src.getManifestAndLock(ctx, pr, r, an)
277293
return err
278294
})
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+
279316
if err != nil {
280317
return nil, nil, err
281318
}
@@ -310,6 +347,27 @@ func (sg *sourceGateway) listPackages(ctx context.Context, pr ProjectRoot, v Ver
310347
ptree, err = sg.src.listPackages(ctx, pr, r)
311348
return err
312349
})
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+
313371
if err != nil {
314372
return pkgtree.PackageTree{}, err
315373
}

0 commit comments

Comments
 (0)