refactor: extract repo setup for tests

This commit is contained in:
Aleksey Kulikov 2021-09-23 16:35:05 +03:00
parent 10b9864219
commit 466f960c7b
26 changed files with 176 additions and 320 deletions

View file

@ -1,21 +1,26 @@
import 'dart:async';
import 'dart:io';
import 'package:path/path.dart' as p;
Future<void> copyRepo({
required Directory from,
required Directory to,
}) async {
final tmpDir = Directory.systemTemp.createTempSync('testrepo');
Future<Directory> setupRepo(Directory repoDir) async {
if (await tmpDir.exists()) {
await tmpDir.delete(recursive: true);
}
await copyRepo(from: repoDir, to: await tmpDir.create());
return tmpDir;
}
Future<void> copyRepo({required Directory from, required Directory to}) async {
await for (final entity in from.list()) {
if (entity is Directory) {
late Directory newDir;
Directory newDir;
if (p.basename(entity.path) == '.gitdir') {
newDir = Directory(p.join(to.absolute.path, '.git'));
} else {
newDir = Directory(p.join(to.absolute.path, p.basename(entity.path)));
}
await newDir.create();
await copyRepo(from: entity.absolute, to: newDir);
await copyRepo(from: entity.absolute, to: await newDir.create());
} else if (entity is File) {
if (p.basename(entity.path) == 'gitignore') {
await entity.copy(p.join(to.path, '.gitignore'));