diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index 11b4b57..3ee7f16 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -53,4 +53,4 @@ jobs: run: flutter pub get - name: Run tests - run: dart test --exclude-tags "remote_fetch" --platform=vm + run: dart test --reporter expanded --exclude-tags "remote_fetch" --platform=vm diff --git a/README.md b/README.md index 4c9d094..a087826 100644 --- a/README.md +++ b/README.md @@ -78,16 +78,12 @@ You can instantiate a `Repository` class with a path to open an existing reposit ```dart final repo = Repository.open('path/to/repository'); // => Repository -// Release memory allocated for Repository object when it's no longer needed -repo.free(); ``` You can create new repository with provided path and optional `bare` argument if you want it to be bare: ```dart final repo = Repository.init(path: 'path/to/folder', bare: true); // => Repository -// Release memory allocated for Repository object when it's no longer needed -repo.free(); ``` You can clone the existing repository at provided url into local path: @@ -97,8 +93,6 @@ final repo = Repository.clone( url: 'https://some.url/', localPath: 'path/to/clone/into', ); // => Repository -// Release memory allocated for Repository object when it's no longer needed -repo.free(); ``` Also you can discover the path to the '.git' directory of repository if you provide a path to subdirectory: @@ -135,9 +129,6 @@ ref.target.sha; // => '821ed6e80627b8769d170a293862f9fc60825226' final oid = repo['821ed6e80627b8769d170a293862f9fc60825226']; // => Oid final commit = Commit.lookup(repo: repo, oid: oid); // => Commit commit.message; // => 'initial commit' - -// Release memory allocated for Repository object when it's no longer needed -repo.free(); ``` #### Writing to repository @@ -160,9 +151,6 @@ Commit.create( tree: tree, parents: [], // empty list for initial commit, 1 parent for regular and 2+ for merge commits ); // => Oid - -// Release memory allocated for Repository object when it's no longer needed -repo.free(); ``` --- diff --git a/lib/src/bindings/remote_callbacks.dart b/lib/src/bindings/remote_callbacks.dart index 47cfeb5..a6c7710 100644 --- a/lib/src/bindings/remote_callbacks.dart +++ b/lib/src/bindings/remote_callbacks.dart @@ -6,6 +6,8 @@ import 'package:libgit2dart/src/bindings/credentials.dart' as credentials_bindings; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; import 'package:libgit2dart/src/bindings/remote.dart' as remote_bindings; +import 'package:libgit2dart/src/bindings/repository.dart' + as repository_bindings; import 'package:libgit2dart/src/util.dart'; class RemoteCallbacks { @@ -112,17 +114,25 @@ class RemoteCallbacks { int bare, Pointer payload, ) { - final repoPointer = Repository.init( + var flagsInt = repositoryCbData!.flags.fold( + 0, + (int acc, e) => acc | e.value, + ); + + if (repositoryCbData!.bare) { + flagsInt |= GitRepositoryInit.bare.value; + } + + final repoPointer = repository_bindings.init( path: repositoryCbData!.path, - bare: repositoryCbData!.bare, - flags: repositoryCbData!.flags, + flags: flagsInt, mode: repositoryCbData!.mode, workdirPath: repositoryCbData!.workdirPath, description: repositoryCbData!.description, templatePath: repositoryCbData!.templatePath, initialHead: repositoryCbData!.initialHead, originUrl: repositoryCbData!.originUrl, - ).pointer; + ); repo[0] = repoPointer; diff --git a/lib/src/bindings/repository.dart b/lib/src/bindings/repository.dart index 91a91b8..6727374 100644 --- a/lib/src/bindings/repository.dart +++ b/lib/src/bindings/repository.dart @@ -321,17 +321,19 @@ void setIdentity({ } /// Retrieve the configured identity to use for reflogs. -Map identity(Pointer repo) { +/// +/// Returns list with name and email respectively. +List identity(Pointer repo) { final name = calloc>(); final email = calloc>(); libgit2.git_repository_ident(name, email, repo); - final identity = {}; + final identity = []; if (name.value == nullptr && email.value == nullptr) { return identity; } else { - identity[name.value.cast().toDartString()] = - email.value.cast().toDartString(); + identity.add(name.value.cast().toDartString()); + identity.add(email.value.cast().toDartString()); } calloc.free(name); diff --git a/lib/src/reference.dart b/lib/src/reference.dart index 1368716..8ea93c7 100644 --- a/lib/src/reference.dart +++ b/lib/src/reference.dart @@ -272,9 +272,6 @@ class Reference { /// Whether reference is a tag. bool get isTag => bindings.isTag(_refPointer); - /// Repository where a reference resides. - Repository get owner => Repository(bindings.owner(_refPointer)); - /// Compares two references. bool equals(Reference other) { return bindings.compare( diff --git a/lib/src/reflog.dart b/lib/src/reflog.dart index 1fe8437..ac71bb3 100644 --- a/lib/src/reflog.dart +++ b/lib/src/reflog.dart @@ -2,13 +2,14 @@ import 'dart:collection'; import 'dart:ffi'; import 'package:libgit2dart/libgit2dart.dart'; import 'package:libgit2dart/src/bindings/libgit2_bindings.dart'; +import 'package:libgit2dart/src/bindings/reference.dart' as reference_bindings; import 'package:libgit2dart/src/bindings/reflog.dart' as bindings; class RefLog with IterableMixin { /// Initializes a new instance of [RefLog] class from provided [Reference]. RefLog(Reference ref) { _reflogPointer = bindings.read( - repoPointer: ref.owner.pointer, + repoPointer: reference_bindings.owner(ref.pointer), name: ref.name, ); _finalizer.attach(this, _reflogPointer, detach: this); @@ -19,7 +20,10 @@ class RefLog with IterableMixin { /// Deletes the reflog for the given reference. static void delete(Reference ref) { - bindings.delete(repoPointer: ref.owner.pointer, name: ref.name); + bindings.delete( + repoPointer: reference_bindings.owner(ref.pointer), + name: ref.name, + ); } /// Renames a reflog. diff --git a/lib/src/repository.dart b/lib/src/repository.dart index 5595ee0..9525801 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -17,13 +17,14 @@ class Repository { /// Initializes a new instance of the [Repository] class from provided /// pointer to repository object in memory. /// - /// **IMPORTANT**: Should be freed to release allocated memory. - /// /// Note: For internal use. Instead, use one of: /// - [Repository.init] /// - [Repository.open] /// - [Repository.clone] - Repository(this._repoPointer); + Repository(Pointer pointer) { + _repoPointer = pointer; + _finalizer.attach(this, _repoPointer, detach: this); + } /// Creates new git repository at the provided [path]. /// @@ -55,8 +56,6 @@ class Repository { /// [originUrl] if set, then after the rest of the repository initialization /// is completed, an "origin" remote will be added pointing to this URL. /// - /// **IMPORTANT**: Should be freed to release allocated memory. - /// /// Throws a [LibGit2Error] if error occured. Repository.init({ required String path, @@ -87,6 +86,8 @@ class Repository { initialHead: initialHead, originUrl: originUrl, ); + + _finalizer.attach(this, _repoPointer, detach: this); } /// Opens repository at provided [path]. @@ -95,13 +96,13 @@ class Repository { /// or to the working directory. For a bare repository, [path] should directly /// point to the repository folder. /// - /// **IMPORTANT**: Should be freed to release allocated memory. - /// /// Throws a [LibGit2Error] if error occured. Repository.open(String path) { libgit2.git_libgit2_init(); _repoPointer = bindings.open(path); + + _finalizer.attach(this, _repoPointer, detach: this); } /// Clones a remote repository at provided [url] into [localPath]. @@ -128,8 +129,6 @@ class Repository { /// [callbacks] is the combination of callback functions from [Callbacks] /// object. /// - /// **IMPORTANT**: Should be freed to release allocated memory. - /// /// Throws a [LibGit2Error] if error occured. Repository.clone({ required String url, @@ -151,6 +150,8 @@ class Repository { checkoutBranch: checkoutBranch, callbacks: callbacks, ); + + _finalizer.attach(this, _repoPointer, detach: this); } late final Pointer _repoPointer; @@ -294,9 +295,12 @@ class Repository { } /// Configured identity to use for reflogs. - /// - /// Returns map with name as key and email as value. - Map get identity => bindings.identity(_repoPointer); + Identity get identity { + final identity = bindings.identity(_repoPointer); + return identity.isNotEmpty + ? Identity(name: identity[0], email: identity[1]) + : const Identity(name: '', email: ''); + } /// Whether repository was a shallow clone. bool get isShallow => bindings.isShallow(_repoPointer); @@ -364,7 +368,10 @@ class Repository { } /// Releases memory allocated for repository object. - void free() => bindings.free(_repoPointer); + void free() { + bindings.free(_repoPointer); + _finalizer.detach(this); + } @override String toString() { @@ -736,6 +743,12 @@ class Repository { } } +// coverage:ignore-start +final _finalizer = Finalizer>( + (pointer) => bindings.free(pointer), +); +// coverage:ignore-end + class RepositoryCallback { /// Values used to override the repository creation and customization process /// during a clone operation. @@ -807,3 +820,11 @@ class RepositoryCallback { /// initialization is completed. final String? originUrl; } + +class Identity { + /// Identity to use for reflogs. + const Identity({required this.name, required this.email}); + + final String name; + final String email; +} diff --git a/lib/src/submodule.dart b/lib/src/submodule.dart index 84d0679..70ea8a8 100644 --- a/lib/src/submodule.dart +++ b/lib/src/submodule.dart @@ -119,9 +119,6 @@ class Submodule { /// This will only work if the submodule is checked out into the working /// directory. /// - /// **IMPORTANT**: Returned [Repository] object should be freed to release - /// allocated memory. - /// /// Throws a [LibGit2Error] if error occured. Repository open() { return Repository(bindings.open(_submodulePointer)); diff --git a/test/annotated_test.dart b/test/annotated_test.dart index 78a4d8b..6ac8165 100644 --- a/test/annotated_test.dart +++ b/test/annotated_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/blame_test.dart b/test/blame_test.dart index dea5099..123f99f 100644 --- a/test/blame_test.dart +++ b/test/blame_test.dart @@ -52,7 +52,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/blob_test.dart b/test/blob_test.dart index c022eeb..c1d47a5 100644 --- a/test/blob_test.dart +++ b/test/blob_test.dart @@ -20,7 +20,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/branch_test.dart b/test/branch_test.dart index 5c0aafa..7b60460 100644 --- a/test/branch_test.dart +++ b/test/branch_test.dart @@ -21,7 +21,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/checkout_test.dart b/test/checkout_test.dart index 7029b9f..d32c428 100644 --- a/test/checkout_test.dart +++ b/test/checkout_test.dart @@ -16,7 +16,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/commit_test.dart b/test/commit_test.dart index 7222b68..bb735ab 100644 --- a/test/commit_test.dart +++ b/test/commit_test.dart @@ -34,7 +34,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/credentials_test.dart b/test/credentials_test.dart index f2cda38..28713cf 100644 --- a/test/credentials_test.dart +++ b/test/credentials_test.dart @@ -5,21 +5,6 @@ import 'package:path/path.dart' as p; import 'package:test/test.dart'; void main() { - final cloneDir = Directory( - p.join(Directory.systemTemp.path, 'credentials_cloned'), - ); - - setUp(() { - if (cloneDir.existsSync()) { - cloneDir.deleteSync(recursive: true); - } - }); - - tearDown(() { - if (cloneDir.existsSync()) { - cloneDir.deleteSync(recursive: true); - } - }); group('Credentials', () { test('initializes username/password credentials', () { final credentials = const UserPass( @@ -78,6 +63,7 @@ void main() { }); test('throws when provided username and password are incorrect', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final callbacks = const Callbacks( credentials: UserPass( username: 'libgit2', @@ -93,11 +79,14 @@ void main() { ), throwsA(isA()), ); + + cloneDir.deleteSync(recursive: true); }); test( 'clones repository with provided keypair', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final keypair = Keypair( username: 'git', pubKey: p.join('test', 'assets', 'keys', 'id_rsa.pub'), @@ -114,12 +103,16 @@ void main() { expect(repo.isEmpty, false); - repo.free(); + if (Platform.isLinux || Platform.isMacOS) { + cloneDir.deleteSync(recursive: true); + } }, testOn: '!linux', ); test('throws when no credentials is provided', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); + expect( () => Repository.clone( url: 'ssh://git@github.com/libgit2/TestGitRepository', @@ -127,9 +120,12 @@ void main() { ), throwsA(isA()), ); + + cloneDir.deleteSync(recursive: true); }); test('throws when provided keypair is invalid', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final keypair = const Keypair( username: 'git', pubKey: 'invalid.pub', @@ -146,9 +142,12 @@ void main() { ), throwsA(isA()), ); + + cloneDir.deleteSync(recursive: true); }); test('throws when provided keypair is incorrect', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final keypair = Keypair( username: 'git', pubKey: p.join('test', 'assets', 'keys', 'id_rsa.pub'), @@ -165,9 +164,12 @@ void main() { ), throwsA(isA()), ); + + cloneDir.deleteSync(recursive: true); }); test('throws when provided credential type is invalid', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final callbacks = const Callbacks( credentials: UserPass( username: 'libgit2', @@ -183,11 +185,14 @@ void main() { ), throwsA(isA()), ); + + cloneDir.deleteSync(recursive: true); }); test( 'clones repository with provided keypair from memory', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub')) .readAsStringSync(); final privateKey = @@ -208,12 +213,15 @@ void main() { expect(repo.isEmpty, false); - repo.free(); + if (Platform.isLinux || Platform.isMacOS) { + cloneDir.deleteSync(recursive: true); + } }, testOn: '!linux', ); test('throws when provided keypair from memory is incorrect', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final pubKey = File(p.join('test', 'assets', 'keys', 'id_rsa.pub')) .readAsStringSync(); final keypair = KeypairFromMemory( @@ -232,9 +240,12 @@ void main() { ), throwsA(isA()), ); + + cloneDir.deleteSync(recursive: true); }); test('throws when provided keypair from agent is incorrect', () { + final cloneDir = Directory.systemTemp.createTempSync('clone'); final callbacks = const Callbacks(credentials: KeypairFromAgent('git')); expect( @@ -245,6 +256,8 @@ void main() { ), throwsA(isA()), ); + + cloneDir.deleteSync(recursive: true); }); }); } diff --git a/test/describe_test.dart b/test/describe_test.dart index 6a6f267..29978e9 100644 --- a/test/describe_test.dart +++ b/test/describe_test.dart @@ -17,7 +17,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/diff_test.dart b/test/diff_test.dart index 3ee7afc..2fa4470 100644 --- a/test/diff_test.dart +++ b/test/diff_test.dart @@ -127,7 +127,6 @@ index e69de29..c217c63 100644 }); tearDown(() { - repo.free(); if (Platform.isLinux || Platform.isMacOS) { tmpDir.deleteSync(recursive: true); } diff --git a/test/index_test.dart b/test/index_test.dart index d6605cc..9a848e4 100644 --- a/test/index_test.dart +++ b/test/index_test.dart @@ -20,7 +20,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); @@ -152,8 +151,6 @@ void main() { p.join('test', 'assets', 'empty_bare.git'), ); expect(() => bare.index.add('config'), throwsA(isA())); - - bare.free(); }); }); @@ -203,8 +200,6 @@ void main() { p.join('test', 'assets', 'empty_bare.git'), ); expect(() => bare.index.addAll([]), throwsA(isA())); - - bare.free(); }); }); @@ -229,8 +224,6 @@ void main() { () => bare.index.updateAll(['not_there']), throwsA(isA()), ); - - bare.free(); }); }); @@ -316,7 +309,6 @@ void main() { expect(() => repo.index.writeTree(), throwsA(isA())); - repo.free(); tmpDir.deleteSync(recursive: true); }); @@ -356,7 +348,6 @@ void main() { expect(conflictedFile.their?.path, 'feature_file'); expect(conflictedFile.toString(), contains('ConflictEntry{')); - conflictRepo.free(); repoDir.deleteSync(recursive: true); }); @@ -381,7 +372,6 @@ void main() { expect(conflictedFile.their?.path, 'conflict_file'); expect(conflictedFile.toString(), contains('ConflictEntry{')); - conflictRepo.free(); repoDir.deleteSync(recursive: true); }); @@ -407,7 +397,6 @@ void main() { expect(conflictedFile.their?.path, 'feature_file'); expect(conflictedFile.toString(), contains('ConflictEntry{')); - conflictRepo.free(); repoDir.deleteSync(recursive: true); }); @@ -432,7 +421,6 @@ void main() { expect(conflictedFile.their?.path, null); expect(conflictedFile.toString(), contains('ConflictEntry{')); - conflictRepo.free(); repoDir.deleteSync(recursive: true); }); @@ -465,7 +453,6 @@ void main() { expect(index.conflicts, isEmpty); expect(index.conflicts['conflict_file'], null); - conflictRepo.free(); repoDir.deleteSync(recursive: true); }); @@ -502,7 +489,6 @@ void main() { expect(index.hasConflicts, false); expect(index.conflicts, isEmpty); - conflictRepo.free(); repoDir.deleteSync(recursive: true); }); diff --git a/test/mailmap_test.dart b/test/mailmap_test.dart index 51ed458..39326f0 100644 --- a/test/mailmap_test.dart +++ b/test/mailmap_test.dart @@ -136,7 +136,6 @@ Santa Claus }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/merge_test.dart b/test/merge_test.dart index 7991982..6f3a276 100644 --- a/test/merge_test.dart +++ b/test/merge_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/note_test.dart b/test/note_test.dart index 6be3a08..f2923ee 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -29,7 +29,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/odb_test.dart b/test/odb_test.dart index 6a722a9..18ffcfd 100644 --- a/test/odb_test.dart +++ b/test/odb_test.dart @@ -20,7 +20,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/oid_test.dart b/test/oid_test.dart index 980449a..45c6e8f 100644 --- a/test/oid_test.dart +++ b/test/oid_test.dart @@ -20,7 +20,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/packbuilder_test.dart b/test/packbuilder_test.dart index ff63c8a..035ea85 100644 --- a/test/packbuilder_test.dart +++ b/test/packbuilder_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/patch_test.dart b/test/patch_test.dart index 7e222e4..055f89d 100644 --- a/test/patch_test.dart +++ b/test/patch_test.dart @@ -50,7 +50,6 @@ index e69de29..0000000 }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/rebase_test.dart b/test/rebase_test.dart index 353f5ef..fc11618 100644 --- a/test/rebase_test.dart +++ b/test/rebase_test.dart @@ -21,7 +21,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/reference_test.dart b/test/reference_test.dart index 4345317..8c485da 100644 --- a/test/reference_test.dart +++ b/test/reference_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/reflog_test.dart b/test/reflog_test.dart index 021d1f8..9bbea43 100644 --- a/test/reflog_test.dart +++ b/test/reflog_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/remote_prune_test.dart b/test/remote_prune_test.dart index 9ac3ee7..c1c5965 100644 --- a/test/remote_prune_test.dart +++ b/test/remote_prune_test.dart @@ -30,8 +30,6 @@ void main() { }); tearDown(() { - originRepo.free(); - clonedRepo.free(); tmpDir.deleteSync(recursive: true); if (cloneDir.existsSync()) { cloneDir.deleteSync(recursive: true); diff --git a/test/remote_test.dart b/test/remote_test.dart index 4d61bbb..3b0e1de 100644 --- a/test/remote_test.dart +++ b/test/remote_test.dart @@ -18,7 +18,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); @@ -474,13 +473,8 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68 ); test('pushes with update reference callback', () { - final originDir = - Directory(p.join(Directory.systemTemp.path, 'origin_testrepo')); + final originDir = Directory.systemTemp.createTempSync('origin'); - if (originDir.existsSync()) { - originDir.deleteSync(recursive: true); - } - originDir.createSync(); copyRepo( from: Directory(p.join('test', 'assets', 'empty_bare.git')), to: originDir, @@ -505,8 +499,9 @@ Total 69 (delta 0), reused 1 (delta 0), pack-reused 68 ); expect(updateRefOutput, {'refs/heads/master': ''}); - originRepo.free(); - originDir.delete(recursive: true); + if (Platform.isLinux || Platform.isMacOS) { + originDir.deleteSync(recursive: true); + } }); test('throws when trying to push to invalid url', () { diff --git a/test/repository_clone_test.dart b/test/repository_clone_test.dart index 0dbf1f4..593bf44 100644 --- a/test/repository_clone_test.dart +++ b/test/repository_clone_test.dart @@ -37,8 +37,6 @@ void main() { expect(clonedRepo.isEmpty, false); expect(clonedRepo.isBare, false); - - clonedRepo.free(); }); test('clones repository as bare', () { @@ -50,8 +48,6 @@ void main() { expect(clonedRepo.isEmpty, false); expect(clonedRepo.isBare, true); - - clonedRepo.free(); }); test('clones repository with provided checkout branch name', () { @@ -65,8 +61,6 @@ void main() { expect(clonedRepo.isEmpty, false); expect(clonedRepo.isBare, true); expect(clonedRepo.head.name, 'refs/heads/feature'); - - clonedRepo.free(); }); test( @@ -82,8 +76,6 @@ void main() { expect(clonedRepo.isBare, false); expect(clonedRepo.remotes, ['test']); expect(clonedRepo.references, contains('refs/remotes/test/master')); - - clonedRepo.free(); }); test('clones repository with provided remote callback ', () { @@ -105,8 +97,6 @@ void main() { expect(clonedRepo.remotes, ['test']); expect(clonedRepo.references, contains('refs/remotes/spec/master')); expect(remote.fetchRefspecs, [fetchRefspec]); - - clonedRepo.free(); }); test('throws when cloning repository with invalid remote callback', () { @@ -132,14 +122,16 @@ void main() { final clonedRepo = Repository.clone( url: tmpDir.path, localPath: cloneDir.path, - repositoryCallback: RepositoryCallback(path: callbackPath.path), + repositoryCallback: RepositoryCallback( + path: callbackPath.path, + bare: true, + ), ); expect(clonedRepo.isEmpty, false); - expect(clonedRepo.isBare, false); - expect(clonedRepo.path, contains('/callbackRepo/.git/')); + expect(clonedRepo.isBare, true); + expect(clonedRepo.path, contains('/callbackRepo/')); - clonedRepo.free(); callbackPath.deleteSync(recursive: true); }); diff --git a/test/repository_empty_test.dart b/test/repository_empty_test.dart index ba19248..7375895 100644 --- a/test/repository_empty_test.dart +++ b/test/repository_empty_test.dart @@ -20,10 +20,6 @@ void main() { repo = Repository.open(p.join('test', 'assets', 'empty_bare.git')); }); - tearDown(() { - repo.free(); - }); - test('opens successfully', () { expect(repo, isA()); }); @@ -52,10 +48,6 @@ void main() { ); }); - tearDown(() { - repo.free(); - }); - test('opens standart repository from working directory successfully', () { expect(repo, isA()); }); @@ -89,12 +81,18 @@ void main() { test('sets identity ', () { repo.setIdentity(name: 'name', email: 'email@email.com'); - expect(repo.identity, {'name': 'email@email.com'}); + + final identity = repo.identity; + expect(identity.name, 'name'); + expect(identity.email, 'email@email.com'); }); test('unsets identity', () { repo.setIdentity(name: null, email: null); - expect(repo.identity, isEmpty); + + final identity = repo.identity; + expect(identity.name, ''); + expect(identity.email, ''); }); test('checks if shallow clone', () { diff --git a/test/repository_init_test.dart b/test/repository_init_test.dart index 2a64a92..c549ceb 100644 --- a/test/repository_init_test.dart +++ b/test/repository_init_test.dart @@ -24,8 +24,6 @@ void main() { expect(repo.path, contains('init_repo')); expect(repo.isBare, true); - - repo.free(); }); test('creates new standard repo at provided path', () { @@ -34,8 +32,6 @@ void main() { expect(repo.path, contains('init_repo/.git/')); expect(repo.isBare, false); expect(repo.isEmpty, true); - - repo.free(); }); test('creates new standard repo with provided options', () { @@ -54,8 +50,6 @@ void main() { 'test repo', ); expect(Remote.lookup(repo: repo, name: 'origin').url, 'test.url'); - - repo.free(); }); }); } diff --git a/test/repository_test.dart b/test/repository_test.dart index 0d7320c..34e0a25 100644 --- a/test/repository_test.dart +++ b/test/repository_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); @@ -165,8 +164,6 @@ void main() { final bare = Repository.open(p.join('test', 'assets', 'empty_bare.git')); expect(() => bare.status, throwsA(isA())); - - bare.free(); }); test('cleans up state', () { diff --git a/test/reset_test.dart b/test/reset_test.dart index 54e3725..2e477cb 100644 --- a/test/reset_test.dart +++ b/test/reset_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/revparse_test.dart b/test/revparse_test.dart index e4bf64c..78821f5 100644 --- a/test/revparse_test.dart +++ b/test/revparse_test.dart @@ -18,7 +18,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/revwalk_test.dart b/test/revwalk_test.dart index a960f71..e491ab0 100644 --- a/test/revwalk_test.dart +++ b/test/revwalk_test.dart @@ -24,7 +24,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/stash_test.dart b/test/stash_test.dart index ca064fa..6f811bc 100644 --- a/test/stash_test.dart +++ b/test/stash_test.dart @@ -24,7 +24,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/submodule_test.dart b/test/submodule_test.dart index 3438b5d..411ee36 100644 --- a/test/submodule_test.dart +++ b/test/submodule_test.dart @@ -20,7 +20,6 @@ void main() { }); tearDown(() { - repo.free(); try { tmpDir.deleteSync(recursive: true); } catch (e) { @@ -99,8 +98,6 @@ void main() { submodule.workdirOid?.sha, '49322bb17d3acc9146f98c97d078513228bbf3c0', ); - - submoduleRepo.free(); }); test('throws when trying to open repository for not initialized submodule', @@ -120,8 +117,6 @@ void main() { expect(submodule.path, 'test'); expect(submodule.url, submoduleUrl); expect(submoduleRepo.isEmpty, false); - - submoduleRepo.free(); }); test('throws when trying to add submodule with wrong url', () { @@ -197,9 +192,6 @@ void main() { updatedSubmRepoConfig['remote.origin.url'].value, 'https://updated.com/', ); - - submRepo.free(); - updatedSubmRepo.free(); }); test('reloads info', () { diff --git a/test/tag_test.dart b/test/tag_test.dart index 49b3cf0..15a7b33 100644 --- a/test/tag_test.dart +++ b/test/tag_test.dart @@ -21,7 +21,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/tree_test.dart b/test/tree_test.dart index e35b6f1..e405c26 100644 --- a/test/tree_test.dart +++ b/test/tree_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/treebuilder_test.dart b/test/treebuilder_test.dart index e83ac15..d2a24de 100644 --- a/test/treebuilder_test.dart +++ b/test/treebuilder_test.dart @@ -19,7 +19,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); }); diff --git a/test/worktree_test.dart b/test/worktree_test.dart index 9dad2a1..0ff6cd9 100644 --- a/test/worktree_test.dart +++ b/test/worktree_test.dart @@ -22,7 +22,6 @@ void main() { }); tearDown(() { - repo.free(); tmpDir.deleteSync(recursive: true); if (worktreeDir.existsSync()) { worktreeDir.deleteSync(recursive: true);