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
|
@ -34,8 +34,6 @@ void main() {
|
|||
expect(remote.url, remoteUrl);
|
||||
expect(remote.pushUrl, '');
|
||||
expect(remote.toString(), contains('Remote{'));
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when provided name for lookup is not found', () {
|
||||
|
@ -56,8 +54,6 @@ void main() {
|
|||
expect(remote.name, 'upstream');
|
||||
expect(remote.url, remoteUrl);
|
||||
expect(remote.pushUrl, '');
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('creates with provided fetchspec', () {
|
||||
|
@ -74,19 +70,12 @@ void main() {
|
|||
expect(remote.url, remoteUrl);
|
||||
expect(remote.pushUrl, '');
|
||||
expect(remote.fetchRefspecs, [spec]);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to create with fetchspec with invalid remote name',
|
||||
() {
|
||||
expect(
|
||||
() => Remote.create(
|
||||
repo: repo,
|
||||
name: '',
|
||||
url: '',
|
||||
fetch: '',
|
||||
),
|
||||
() => Remote.create(repo: repo, name: '', url: '', fetch: ''),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -101,8 +90,6 @@ void main() {
|
|||
|
||||
Remote.delete(repo: repo, name: remote.name);
|
||||
expect(repo.remotes.length, 1);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to delete non existing remote', () {
|
||||
|
@ -118,16 +105,13 @@ void main() {
|
|||
final problems = Remote.rename(
|
||||
repo: repo,
|
||||
oldName: remoteName,
|
||||
newName: 'new',
|
||||
newName: 'renamed',
|
||||
);
|
||||
expect(problems, isEmpty);
|
||||
expect(remote.name, isNot('new'));
|
||||
expect(remote.name, isNot('renamed'));
|
||||
|
||||
final newRemote = Remote.lookup(repo: repo, name: 'new');
|
||||
expect(newRemote.name, 'new');
|
||||
|
||||
newRemote.free();
|
||||
remote.free();
|
||||
final renamedRemote = Remote.lookup(repo: repo, name: 'renamed');
|
||||
expect(renamedRemote.name, 'renamed');
|
||||
});
|
||||
|
||||
test('returns list of non-default refspecs that cannot be renamed', () {
|
||||
|
@ -142,8 +126,6 @@ void main() {
|
|||
Remote.rename(repo: repo, oldName: remote.name, newName: 'renamed'),
|
||||
['+refs/*:refs/*'],
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when renaming with invalid names', () {
|
||||
|
@ -154,17 +136,12 @@ void main() {
|
|||
});
|
||||
|
||||
test('sets url', () {
|
||||
final remote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(remote.url, remoteUrl);
|
||||
expect(Remote.lookup(repo: repo, name: remoteName).url, remoteUrl);
|
||||
|
||||
const newUrl = 'git://new/url.git';
|
||||
Remote.setUrl(repo: repo, remote: remoteName, url: newUrl);
|
||||
|
||||
final newRemote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(newRemote.url, newUrl);
|
||||
|
||||
newRemote.free();
|
||||
remote.free();
|
||||
expect(Remote.lookup(repo: repo, name: remoteName).url, newUrl);
|
||||
});
|
||||
|
||||
test('throws when trying to set invalid url name', () {
|
||||
|
@ -178,10 +155,7 @@ void main() {
|
|||
const newUrl = 'git://new/url.git';
|
||||
Remote.setPushUrl(repo: repo, remote: remoteName, url: newUrl);
|
||||
|
||||
final remote = Remote.lookup(repo: repo, name: remoteName);
|
||||
expect(remote.pushUrl, newUrl);
|
||||
|
||||
remote.free();
|
||||
expect(Remote.lookup(repo: repo, name: remoteName).pushUrl, newUrl);
|
||||
});
|
||||
|
||||
test('throws when trying to set invalid push url name', () {
|
||||
|
@ -215,14 +189,11 @@ void main() {
|
|||
refspec.rTransform('refs/remotes/origin/master'),
|
||||
'refs/heads/master',
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to transform refspec with invalid reference name',
|
||||
() {
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
final refspec = remote.getRefspec(0);
|
||||
final refspec = Remote.lookup(repo: repo, name: 'origin').getRefspec(0);
|
||||
|
||||
expect(
|
||||
() => refspec.transform('invalid/name'),
|
||||
|
@ -233,8 +204,6 @@ void main() {
|
|||
() => refspec.rTransform('invalid/name'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('adds fetch refspec', () {
|
||||
|
@ -252,8 +221,6 @@ void main() {
|
|||
'+refs/test/*:refs/test/remotes/*',
|
||||
],
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add fetch refspec for invalid remote name', () {
|
||||
|
@ -276,8 +243,6 @@ void main() {
|
|||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
expect(remote.pushRefspecs.length, 1);
|
||||
expect(remote.pushRefspecs, ['+refs/test/*:refs/test/remotes/*']);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add push refspec for invalid remote name', () {
|
||||
|
@ -308,8 +273,6 @@ void main() {
|
|||
(refs.first['oid']! as Oid).sha,
|
||||
'49322bb17d3acc9146f98c97d078513228bbf3c0',
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -319,8 +282,6 @@ void main() {
|
|||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
expect(() => remote.ls(), throwsA(isA<LibGit2Error>()));
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -350,8 +311,6 @@ void main() {
|
|||
expect(stats.indexedDeltas, 3);
|
||||
expect(stats.receivedBytes, 0);
|
||||
expect(stats.toString(), contains('TransferProgress{'));
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -384,8 +343,6 @@ void main() {
|
|||
expect(stats.indexedDeltas, 3);
|
||||
expect(stats.receivedBytes, 0);
|
||||
expect(stats.toString(), contains('TransferProgress{'));
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -412,8 +369,6 @@ void main() {
|
|||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -426,8 +381,6 @@ void main() {
|
|||
() => remote.fetch(),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
remote.free();
|
||||
});
|
||||
|
||||
test(
|
||||
|
@ -442,9 +395,8 @@ void main() {
|
|||
|
||||
TransferProgress? callbackStats;
|
||||
void tp(TransferProgress stats) => callbackStats = stats;
|
||||
final callbacks = Callbacks(transferProgress: tp);
|
||||
|
||||
final stats = remote.fetch(callbacks: callbacks);
|
||||
final stats = remote.fetch(callbacks: Callbacks(transferProgress: tp));
|
||||
|
||||
expect(stats.totalObjects == callbackStats?.totalObjects, true);
|
||||
expect(stats.indexedObjects == callbackStats?.indexedObjects, true);
|
||||
|
@ -453,8 +405,6 @@ void main() {
|
|||
expect(stats.totalDeltas == callbackStats?.totalDeltas, true);
|
||||
expect(stats.indexedDeltas == callbackStats?.indexedDeltas, true);
|
||||
expect(stats.receivedBytes == callbackStats?.receivedBytes, true);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -475,16 +425,10 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
final remote = Remote.lookup(repo: repo, name: 'libgit2');
|
||||
|
||||
final sidebandOutput = StringBuffer();
|
||||
void sideband(String message) {
|
||||
sidebandOutput.write(message);
|
||||
}
|
||||
void sideband(String message) => sidebandOutput.write(message);
|
||||
|
||||
final callbacks = Callbacks(sidebandProgress: sideband);
|
||||
|
||||
remote.fetch(callbacks: callbacks);
|
||||
remote.fetch(callbacks: Callbacks(sidebandProgress: sideband));
|
||||
expect(sidebandOutput.toString(), sidebandMessage);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -525,12 +469,8 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
});
|
||||
}
|
||||
|
||||
final callbacks = Callbacks(updateTips: updateTips);
|
||||
|
||||
remote.fetch(callbacks: callbacks);
|
||||
remote.fetch(callbacks: Callbacks(updateTips: updateTips));
|
||||
expect(updateTipsOutput, tipsExpected);
|
||||
|
||||
remote.free();
|
||||
},
|
||||
tags: 'remote_fetch',
|
||||
);
|
||||
|
@ -557,16 +497,16 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
updateRefOutput[refname] = message;
|
||||
}
|
||||
|
||||
final callbacks = Callbacks(pushUpdateReference: updateRef);
|
||||
|
||||
remote.push(refspecs: ['refs/heads/master'], callbacks: callbacks);
|
||||
remote.push(
|
||||
refspecs: ['refs/heads/master'],
|
||||
callbacks: Callbacks(pushUpdateReference: updateRef),
|
||||
);
|
||||
expect(
|
||||
Commit.lookup(repo: originRepo, oid: originRepo.head.target).oid.sha,
|
||||
'821ed6e80627b8769d170a293862f9fc60825226',
|
||||
);
|
||||
expect(updateRefOutput, {'refs/heads/master': ''});
|
||||
|
||||
remote.free();
|
||||
originRepo.free();
|
||||
originDir.delete(recursive: true);
|
||||
});
|
||||
|
@ -579,8 +519,26 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68
|
|||
() => remote.push(refspecs: ['refs/heads/master']),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
remote.free();
|
||||
test('manually releases allocated memory', () {
|
||||
final remote = Remote.lookup(repo: repo, name: 'origin');
|
||||
expect(() => remote.free(), returnsNormally);
|
||||
});
|
||||
});
|
||||
|
||||
group('RemoteCallback', () {
|
||||
test('initializes and returns values', () {
|
||||
const remoteCallback = RemoteCallback(
|
||||
name: 'name',
|
||||
url: 'url',
|
||||
fetch: 'fetchRefspec',
|
||||
);
|
||||
|
||||
expect(remoteCallback, isA<RemoteCallback>());
|
||||
expect(remoteCallback.name, 'name');
|
||||
expect(remoteCallback.url, 'url');
|
||||
expect(remoteCallback.fetch, 'fetchRefspec');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue