mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
refactor: extract repo setup for tests
This commit is contained in:
parent
10b9864219
commit
466f960c7b
26 changed files with 176 additions and 320 deletions
|
@ -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'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue