mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
test(remote): add tests for prune() method
This commit is contained in:
parent
4c7a096fe3
commit
934b601d68
1 changed files with 69 additions and 0 deletions
69
test/remote_prune_test.dart
Normal file
69
test/remote_prune_test.dart
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:libgit2dart/src/git_types.dart';
|
||||||
|
import 'package:test/test.dart';
|
||||||
|
import 'package:libgit2dart/libgit2dart.dart';
|
||||||
|
import 'helpers/util.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
late Repository originRepo;
|
||||||
|
late Repository clonedRepo;
|
||||||
|
late Directory tmpDir;
|
||||||
|
late Remote remote;
|
||||||
|
final cloneDir = Directory('${Directory.systemTemp.path}/cloned');
|
||||||
|
|
||||||
|
setUp(() async {
|
||||||
|
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||||
|
if (await cloneDir.exists()) {
|
||||||
|
cloneDir.delete(recursive: true);
|
||||||
|
}
|
||||||
|
originRepo = Repository.open(tmpDir.path);
|
||||||
|
clonedRepo = Repository.clone(
|
||||||
|
url: tmpDir.path,
|
||||||
|
localPath: cloneDir.path,
|
||||||
|
);
|
||||||
|
originRepo.branches['feature'].delete();
|
||||||
|
remote = clonedRepo.remotes['origin'];
|
||||||
|
});
|
||||||
|
|
||||||
|
tearDown(() async {
|
||||||
|
remote.free();
|
||||||
|
originRepo.free();
|
||||||
|
clonedRepo.free();
|
||||||
|
await tmpDir.delete(recursive: true);
|
||||||
|
if (await cloneDir.exists()) {
|
||||||
|
cloneDir.delete(recursive: true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
group('Remote', () {
|
||||||
|
test('fetch() does not prune branch by default', () {
|
||||||
|
remote.fetch();
|
||||||
|
expect(clonedRepo.branches.list(), contains('origin/feature'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fetch() successfully prunes branch with provided flag', () {
|
||||||
|
remote.fetch(prune: GitFetchPrune.prune);
|
||||||
|
expect(clonedRepo.branches.list(), isNot(contains('origin/feature')));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fetch() does not prune branch with provided flag', () {
|
||||||
|
remote.fetch(prune: GitFetchPrune.noPrune);
|
||||||
|
expect(clonedRepo.branches.list(), contains('origin/feature'));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('prune() successfully prunes branches', () {
|
||||||
|
var pruned = <String>[];
|
||||||
|
void updateTips(String refname, Oid oldOid, Oid newOid) {
|
||||||
|
pruned.add(refname);
|
||||||
|
}
|
||||||
|
|
||||||
|
final callbacks = Callbacks(updateTips: updateTips);
|
||||||
|
|
||||||
|
remote.fetch(prune: GitFetchPrune.noPrune);
|
||||||
|
expect(clonedRepo.branches.list(), contains('origin/feature'));
|
||||||
|
|
||||||
|
remote.prune(callbacks);
|
||||||
|
expect(pruned, contains('refs/remotes/origin/feature'));
|
||||||
|
expect(clonedRepo.branches.list(), isNot(contains('origin/feature')));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue