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

@ -72,8 +72,7 @@ void main() {
});
test('checkouts reference', () {
final masterHead = Commit.lookup(repo: repo, oid: repo['821ed6e']);
final masterTree = masterHead.tree;
final masterTree = Commit.lookup(repo: repo, oid: repo['821ed6e']).tree;
expect(
masterTree.entries.any((e) => e.name == 'another_feature_file'),
false,
@ -82,19 +81,12 @@ void main() {
Checkout.reference(repo: repo, name: 'refs/heads/feature');
final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
final featureTree = featureHead.tree;
final repoHead = repo.head;
// does not change HEAD
expect(repoHead.target, isNot(featureHead.oid));
expect(repo.head.target, isNot(featureHead.oid));
expect(
featureTree.entries.any((e) => e.name == 'another_feature_file'),
true,
);
repoHead.free();
featureTree.free();
featureHead.free();
masterTree.free();
masterHead.free();
});
test(
@ -111,20 +103,14 @@ void main() {
});
test('checkouts commit', () {
final index = repo.index;
expect(index.find('another_feature_file'), equals(false));
expect(repo.index.find('another_feature_file'), equals(false));
final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
Checkout.commit(repo: repo, commit: featureHead);
final repoHead = repo.head;
// does not change HEAD
expect(repoHead.target, isNot(featureHead.oid));
expect(index.find('another_feature_file'), equals(true));
repoHead.free();
featureHead.free();
index.free();
expect(repo.head.target, isNot(featureHead.oid));
expect(repo.index.find('another_feature_file'), equals(true));
});
test('checkouts commit with provided path', () {
@ -135,35 +121,27 @@ void main() {
paths: ['another_feature_file'],
);
final repoHead = repo.head;
// does not change HEAD
expect(repoHead.target, isNot(featureHead.oid));
expect(repo.head.target, isNot(featureHead.oid));
expect(
repo.status,
{
'another_feature_file': {GitStatus.indexNew}
},
);
repoHead.free();
featureHead.free();
});
test(
'throws when trying to checkout commit with invalid alternative '
'directory', () {
final commit = Commit.lookup(repo: repo, oid: repo['5aecfa0']);
expect(
() => Checkout.commit(
repo: repo,
commit: commit,
commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']),
directory: 'not/there',
),
throwsA(isA<LibGit2Error>()),
);
commit.free();
});
test('checkouts with alrenative directory', () {
@ -208,8 +186,7 @@ void main() {
});
test('performs dry run checkout', () {
final index = repo.index;
expect(index.length, 4);
expect(repo.index.length, 4);
final file = File(p.join(repo.workdir, 'another_feature_file'));
expect(file.existsSync(), false);
@ -218,10 +195,8 @@ void main() {
name: 'refs/heads/feature',
strategy: {GitCheckout.dryRun},
);
expect(index.length, 4);
expect(repo.index.length, 4);
expect(file.existsSync(), false);
index.free();
});
});
}