mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
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:
parent
94c40f9a94
commit
a3213a88a2
103 changed files with 2278 additions and 2595 deletions
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue