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

@ -38,28 +38,21 @@ void main() {
name: worktreeName,
path: worktreeDir.path,
);
final branches = repo.branches;
expect(repo.worktrees, [worktreeName]);
expect(branches.any((branch) => branch.name == worktreeName), true);
expect(repo.branches.any((branch) => branch.name == worktreeName), true);
expect(worktree.name, worktreeName);
expect(worktree.path, contains('worktree'));
expect(worktree.isLocked, false);
expect(worktree.toString(), contains('Worktree{'));
expect(File(p.join(worktreeDir.path, '.git')).existsSync(), true);
for (final branch in branches) {
branch.free();
}
worktree.free();
});
test('creates worktree at provided path from provided reference', () {
final head = RevParse.single(repo: repo, spec: 'HEAD') as Commit;
final worktreeBranch = Branch.create(
repo: repo,
name: 'v1',
target: head,
target: RevParse.single(repo: repo, spec: 'HEAD') as Commit,
);
final ref = Reference.lookup(repo: repo, name: 'refs/heads/v1');
expect(repo.worktrees, <String>[]);
@ -83,14 +76,6 @@ void main() {
expect(repo.worktrees, <String>[]);
expect(worktreeBranch.isCheckedOut, false);
expect(branches.any((branch) => branch.name == 'v1'), true);
for (final branch in branches) {
branch.free();
}
worktreeBranch.free();
ref.free();
head.free();
worktree.free();
});
test('throws when trying to create worktree with invalid name or path', () {
@ -113,19 +98,16 @@ void main() {
});
test('lookups worktree', () {
final worktree = Worktree.create(
Worktree.create(
repo: repo,
name: worktreeName,
path: worktreeDir.path,
);
final lookedupWorktree = Worktree.lookup(repo: repo, name: worktreeName);
final worktree = Worktree.lookup(repo: repo, name: worktreeName);
expect(lookedupWorktree.name, worktreeName);
expect(lookedupWorktree.path, contains('worktree'));
expect(lookedupWorktree.isLocked, false);
lookedupWorktree.free();
worktree.free();
expect(worktree.name, worktreeName);
expect(worktree.path, contains('worktree'));
expect(worktree.isLocked, false);
});
test('throws when trying to lookup and error occurs', () {
@ -148,8 +130,6 @@ void main() {
worktree.unlock();
expect(worktree.isLocked, false);
worktree.free();
});
test('prunes worktree', () {
@ -170,8 +150,6 @@ void main() {
worktree.prune();
expect(repo.worktrees, <String>[]);
worktree.free();
});
test('throws when trying get list of worktrees and error occurs', () {
@ -180,5 +158,14 @@ void main() {
throwsA(isA<LibGit2Error>()),
);
});
test('manually releases allocated memory', () {
final worktree = Worktree.create(
repo: repo,
name: worktreeName,
path: worktreeDir.path,
);
expect(() => worktree.free(), returnsNormally);
});
});
}