refactor!: use Finalizer to automatically free allocated memory for objects (#48)

BREAKING CHANGE: signature change for remote and repository callbacks during repository clone operation.
This commit is contained in:
Aleksey Kulikov 2022-04-28 11:04:48 +03:00 committed by GitHub
parent 94c40f9a94
commit a3213a88a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
103 changed files with 2278 additions and 2595 deletions

View file

@ -25,68 +25,48 @@ void main() {
group('Reset', () {
test('resets with hard', () {
var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
expect(file.readAsStringSync(), 'Feature edit\n');
repo.reset(oid: repo[sha], resetType: GitReset.hard);
contents = file.readAsStringSync();
expect(contents, isEmpty);
expect(file.readAsStringSync(), isEmpty);
});
test('resets with soft', () {
var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
expect(file.readAsStringSync(), 'Feature edit\n');
repo.reset(oid: repo[sha], resetType: GitReset.soft);
contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
expect(file.readAsStringSync(), 'Feature edit\n');
final index = repo.index;
final diff = Diff.indexToWorkdir(repo: repo, index: index);
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
expect(diff.deltas, isEmpty);
index.free();
});
test('resets with mixed', () {
var contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
expect(file.readAsStringSync(), 'Feature edit\n');
repo.reset(oid: repo[sha], resetType: GitReset.mixed);
contents = file.readAsStringSync();
expect(contents, 'Feature edit\n');
expect(file.readAsStringSync(), 'Feature edit\n');
final index = repo.index;
final diff = Diff.indexToWorkdir(repo: repo, index: index);
final diff = Diff.indexToWorkdir(repo: repo, index: repo.index);
expect(diff.deltas.length, 1);
index.free();
});
group('resetDefault', () {
test('updates entry in the index', () {
file.writeAsStringSync('new edit');
final index = repo.index;
index.add('feature_file');
repo.index.add('feature_file');
expect(repo.status['feature_file'], {GitStatus.indexModified});
final head = repo.head;
repo.resetDefault(oid: head.target, pathspec: ['feature_file']);
repo.resetDefault(oid: repo.head.target, pathspec: ['feature_file']);
expect(repo.status['feature_file'], {GitStatus.wtModified});
head.free();
index.free();
});
test('throws when pathspec list is empty', () {
final head = repo.head;
expect(
() => repo.resetDefault(oid: head.target, pathspec: []),
() => repo.resetDefault(oid: repo.head.target, pathspec: []),
throwsA(isA<LibGit2Error>()),
);
head.free();
});
});
});