initCachedRepo function

Future<void> initCachedRepo(
  1. Directory target, {
  2. required String key,
  3. required CachedRepoBuilder build,
})

Copies the repo template key into target.

The template is built only once per isolate (i.e. once per test file): the first call with a given key runs build with a fresh template directory; later calls with the same key skip build and only copy the template into target using a pure Dart directory copy — no git processes are spawned for a copy.

Contract: within one isolate a key must always map to the same recipe. The first builder wins; later builders with the same key are ignored. Keys starting with gg_git/ are reserved for the helpers of this package.

target must be empty or not existing. Template directories live in the system temp directory for the lifetime of the process (similar to the parent directories created by initTestDir).

Implementation

Future<void> initCachedRepo(
  Directory target, {
  required String key,
  required CachedRepoBuilder build,
}) async {
  final template = await _memoized(
    _localTemplates,
    key,
    () => _buildLocalTemplate(key, build),
  );

  await _prepareTarget(target);
  _copyDirSync(template, target);
}