feat(repository): add ability to pass callbacks for remote and repository creation during clone

This commit is contained in:
Aleksey Kulikov 2021-09-27 11:19:00 +03:00
parent b1f112a30d
commit 6d48ae742c
4 changed files with 161 additions and 6 deletions

View file

@ -20,11 +20,13 @@ void main() {
tearDown(() async {
repo.free();
await tmpDir.delete(recursive: true);
cloneDir.delete(recursive: true);
if (await cloneDir.exists()) {
cloneDir.delete(recursive: true);
}
});
group('Repository.clone', () {
test('successfully clones repository', () async {
test('successfully clones repository', () {
final clonedRepo = Repository.clone(
url: tmpDir.path,
localPath: cloneDir.path,
@ -36,7 +38,7 @@ void main() {
clonedRepo.free();
});
test('successfully clones repository as bare', () async {
test('successfully clones repository as bare', () {
final clonedRepo = Repository.clone(
url: tmpDir.path,
localPath: cloneDir.path,
@ -50,7 +52,7 @@ void main() {
});
test('successfully clones repository with provided checkout branch name',
() async {
() {
final clonedRepo = Repository.clone(
url: tmpDir.path,
localPath: cloneDir.path,
@ -64,5 +66,77 @@ void main() {
clonedRepo.free();
});
test('successfully clones repository with provided remote callback', () {
Remote remote(Repository repo, String name, String url) =>
repo.remotes.create(name: 'test', url: tmpDir.path);
final clonedRepo = Repository.clone(
url: tmpDir.path,
localPath: cloneDir.path,
remote: remote,
);
expect(clonedRepo.isEmpty, false);
expect(clonedRepo.isBare, false);
expect(clonedRepo.remotes.list, ['test']);
expect(clonedRepo.references.list, contains('refs/remotes/test/master'));
clonedRepo.free();
});
test('throws when cloning repository with invalid remote callback', () {
Remote remote(Repository repo, String name, String url) =>
repo.remotes.create(name: '', url: '');
expect(
() => Repository.clone(
url: tmpDir.path,
localPath: cloneDir.path,
remote: remote,
),
throwsA(isA<LibGit2Error>()),
);
});
test('successfully clones repository with provided repository callback',
() async {
final callbackPath =
Directory('${Directory.systemTemp.path}/callbackRepo');
if (await callbackPath.exists()) {
callbackPath.delete(recursive: true);
}
callbackPath.create();
Repository repository(String path, bool bare) =>
Repository.init(path: callbackPath.path);
final clonedRepo = Repository.clone(
url: tmpDir.path,
localPath: cloneDir.path,
repository: repository,
);
expect(clonedRepo.isEmpty, false);
expect(clonedRepo.isBare, false);
expect(clonedRepo.path, '${callbackPath.path}/.git/');
clonedRepo.free();
callbackPath.delete(recursive: true);
});
test('throws when cloning repository with invalid repository callback', () {
Repository repository(String path, bool bare) =>
Repository.init(path: '');
expect(
() => Repository.clone(
url: tmpDir.path,
localPath: cloneDir.path,
repository: repository,
),
throwsA(isA<LibGit2Error>()),
);
});
});
}