initCachedRepoPair function
Future<(Directory, Directory)>
initCachedRepoPair({
- required String key,
- required CachedRepoPairBuilder build,
Returns a fresh copy of the local/remote template pair key.
The template pair is built only once per isolate by calling build with
two fresh template directories. Every call returns a new copy of both
directories. When the local template has an origin remote, the copy's
origin is rewired to the copied remote via git remote set-url — the
only git process spawned per copy.
The same key contract as in initCachedRepo applies. The caller owns
the returned directories and should delete them in tearDown.
Implementation
Future<(Directory local, Directory remote)> initCachedRepoPair({
required String key,
required CachedRepoPairBuilder build,
}) async {
final (templateLocal, templateRemote) = await _memoized(
_pairTemplates,
key,
() => _buildPairTemplate(key, build),
);
final local = await Directory.systemTemp.createTemp('gg_git_copy_local_');
final remote = await Directory.systemTemp.createTemp('gg_git_copy_remote_');
_copyDirSync(templateLocal, local);
_copyDirSync(templateRemote, remote);
if (_hasOriginRemote(templateLocal)) {
final result = await ggRunProcess('git', [
'remote',
'set-url',
'origin',
remote.path,
], workingDirectory: local.path);
if (result.exitCode != 0) {
throw Exception('Could not set remote url: ${result.stderr}');
}
}
return (local, remote);
}