From 94b4116adf23d58a5357fe7eb5847a7c4899ed51 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Mon, 30 Aug 2021 16:45:37 +0300 Subject: [PATCH] feat(commit): add ability to create commit with different number of parents --- lib/src/bindings/commit.dart | 24 ++-- lib/src/bindings/oid.dart | 20 +++ lib/src/commit.dart | 45 ++----- lib/src/config.dart | 1 - lib/src/index.dart | 18 +-- lib/src/odb.dart | 5 +- lib/src/oid.dart | 28 ++-- lib/src/reference.dart | 13 +- lib/src/reflog.dart | 1 - lib/src/repository.dart | 35 ++--- lib/src/signature.dart | 1 - lib/src/tree.dart | 1 - test/commit_test.dart | 244 +++++++++++++++++------------------ test/odb_test.dart | 5 +- test/oid_test.dart | 36 +++--- 15 files changed, 217 insertions(+), 260 deletions(-) diff --git a/lib/src/bindings/commit.dart b/lib/src/bindings/commit.dart index e90bb8f..b20c856 100644 --- a/lib/src/bindings/commit.dart +++ b/lib/src/bindings/commit.dart @@ -58,19 +58,19 @@ Pointer create( final messageEncodingC = messageEncoding?.toNativeUtf8().cast() ?? nullptr; final messageC = message.toNativeUtf8().cast(); - late final Pointer> parentsC; + Pointer> parentsC = + calloc.call>(parentCount); if (parents.isNotEmpty) { - parentsC = calloc(parentCount); - for (var i = 0; i < parentCount; i++) { final oid = oid_bindings.fromSHA(parents[i]); - final commit = lookup(repo, oid); - parentsC[i] = commit; + var commit = calloc(); + commit = lookup(repo, oid).cast(); + parentsC[i] = commit.cast(); } } else { - throw UnimplementedError( - 'Writing commit without parents is not implemented'); + final commit = calloc(); + parentsC[0] = commit.cast(); } final error = libgit2.git_commit_create( @@ -89,6 +89,9 @@ Pointer create( calloc.free(updateRefC); calloc.free(messageEncodingC); calloc.free(messageC); + for (var i = 0; i < parentCount; i++) { + free(parentsC[i]); + } calloc.free(parentsC); if (error < 0) { @@ -134,7 +137,7 @@ int parentCount(Pointer commit) => Pointer parentId(Pointer commit, int n) { final parentOid = libgit2.git_commit_parent_id(commit, n); - if (parentOid is int && parentOid as int < 0) { + if (parentOid == nullptr) { throw LibGit2Error(libgit2.git_error_last()); } else { return parentOid; @@ -163,8 +166,5 @@ Pointer tree(Pointer commit) { Pointer owner(Pointer commit) => libgit2.git_commit_owner(commit); -/// Close an open commit. -/// -/// IMPORTANT: It is necessary to call this method when you stop using a commit. -/// Failure to do so will cause a memory leak. +/// Close an open commit to release memory. void free(Pointer commit) => libgit2.git_commit_free(commit); diff --git a/lib/src/bindings/oid.dart b/lib/src/bindings/oid.dart index 08fbc27..1dd40c5 100644 --- a/lib/src/bindings/oid.dart +++ b/lib/src/bindings/oid.dart @@ -38,6 +38,26 @@ Pointer fromSHA(String hex) { } } +/// Copy an already raw oid into a git_oid structure. +/// +/// Throws a [LibGit2Error] if error occured. +Pointer fromRaw(Array raw) { + final out = calloc(); + var rawC = calloc(20); + for (var i = 0; i < 20; i++) { + rawC[i] = raw[i]; + } + final error = libgit2.git_oid_fromraw(out, rawC); + + calloc.free(rawC); + + if (error < 0) { + throw LibGit2Error(libgit2.git_error_last()); + } else { + return out; + } +} + /// Format a git_oid into a hex string. /// /// Throws a [LibGit2Error] if error occured. diff --git a/lib/src/commit.dart b/lib/src/commit.dart index f5365ac..004a714 100644 --- a/lib/src/commit.dart +++ b/lib/src/commit.dart @@ -1,7 +1,8 @@ import 'dart:ffi'; - import 'bindings/libgit2_bindings.dart'; import 'bindings/commit.dart' as bindings; +import 'bindings/oid.dart' as oid_bindings; +import 'bindings/tree.dart' as tree_bindings; import 'repository.dart'; import 'oid.dart'; import 'signature.dart'; @@ -38,30 +39,13 @@ class Commit { required Signature author, required Signature commiter, required String treeSHA, - required List parentsSHA, + required List parents, String? updateRef, String? messageEncoding, }) { - libgit2.git_libgit2_init(); - - final parentCount = parentsSHA.length; - late final Tree tree; - - if (treeSHA.length == 40) { - final treeOid = Oid.fromSHA(treeSHA); - tree = Tree.lookup( - repo.pointer, - treeOid.pointer, - ); - } else { - final odb = repo.odb; - final treeOid = Oid.fromShortSHA(treeSHA, odb); - tree = Tree.lookup( - repo.pointer, - treeOid.pointer, - ); - odb.free(); - } + final treeOid = oid_bindings.fromStrN(treeSHA); + final tree = + Tree(tree_bindings.lookupPrefix(repo.pointer, treeOid, treeSHA.length)); final result = Oid(bindings.create( repo.pointer, @@ -71,12 +55,11 @@ class Commit { messageEncoding, message, tree.pointer, - parentCount, - parentsSHA, + parents.length, + parents, )); tree.free(); - libgit2.git_libgit2_init(); return result; } @@ -105,18 +88,13 @@ class Commit { /// Returns list of parent commits. /// /// Throws a [LibGit2Error] if error occured. - List get parents { - var parents = []; + List get parents { + var parents = []; final parentCount = bindings.parentCount(_commitPointer); for (var i = 0; i < parentCount; i++) { final parentOid = bindings.parentId(_commitPointer, i); - - if (parentOid != nullptr) { - final owner = bindings.owner(_commitPointer); - final commit = bindings.lookup(owner, parentOid); - parents.add(Commit(commit)); - } + parents.add(Oid(parentOid)); } return parents; @@ -128,6 +106,5 @@ class Commit { /// Releases memory allocated for commit object. void free() { bindings.free(_commitPointer); - libgit2.git_libgit2_shutdown(); } } diff --git a/lib/src/config.dart b/lib/src/config.dart index 3f6dcb3..b6b5370 100644 --- a/lib/src/config.dart +++ b/lib/src/config.dart @@ -142,6 +142,5 @@ class Config { /// Releases memory allocated for config object. void free() { bindings.free(_configPointer); - libgit2.git_libgit2_shutdown(); } } diff --git a/lib/src/index.dart b/lib/src/index.dart index 567c70f..b3dfe1e 100644 --- a/lib/src/index.dart +++ b/lib/src/index.dart @@ -3,10 +3,9 @@ import 'package:ffi/ffi.dart'; import 'package:libgit2dart/src/tree.dart'; import 'bindings/libgit2_bindings.dart'; import 'bindings/index.dart' as bindings; -import 'bindings/repository.dart' as repo_bindings; -import 'odb.dart'; import 'oid.dart'; import 'enums.dart'; +import 'repository.dart'; import 'util.dart'; class Index { @@ -101,15 +100,9 @@ class Index { } else if (target is Tree) { tree = target; } else if (isValidShaHex(target as String)) { - if (target.length == 40) { - oid = Oid.fromSHA(target); - tree = Tree.lookup(bindings.owner(_indexPointer), oid.pointer); - } else { - final odb = Odb(repo_bindings.odb(bindings.owner(_indexPointer))); - oid = Oid.fromShortSHA(target, odb); - odb.free(); - tree = Tree.lookup(bindings.owner(_indexPointer), oid.pointer); - } + final repo = Repository(bindings.owner(_indexPointer)); + oid = Oid.fromSHA(repo, target); + tree = Tree.lookup(repo.pointer, oid.pointer); } else { throw ArgumentError.value( '$target should be either Oid object, SHA hex string or Tree object'); @@ -146,7 +139,6 @@ class Index { /// Releases memory allocated for index object. void free() { bindings.free(_indexPointer); - libgit2.git_libgit2_shutdown(); } } @@ -158,7 +150,7 @@ class IndexEntry { late final Pointer _indexEntryPointer; /// Unique identity of the index entry. - Oid get id => Oid.fromSHA(sha); + Oid get id => Oid.fromRaw(_indexEntryPointer.ref.id); set id(Oid oid) => _indexEntryPointer.ref.id = oid.pointer.ref; diff --git a/lib/src/odb.dart b/lib/src/odb.dart index 44eaf10..a19c400 100644 --- a/lib/src/odb.dart +++ b/lib/src/odb.dart @@ -10,9 +10,11 @@ class Odb { libgit2.git_libgit2_init(); } - /// Pointer to memory address for allocated oid object. late final Pointer _odbPointer; + /// Pointer to memory address for allocated oid object. + Pointer get pointer => _odbPointer; + /// Determine if an object can be found in the object database by an abbreviated object ID. /// /// Throws a [LibGit2Error] if error occured. @@ -26,6 +28,5 @@ class Odb { /// Releases memory allocated for odb object. void free() { bindings.free(_odbPointer); - libgit2.git_libgit2_shutdown(); } } diff --git a/lib/src/oid.dart b/lib/src/oid.dart index 8134ef9..c241e84 100644 --- a/lib/src/oid.dart +++ b/lib/src/oid.dart @@ -1,7 +1,7 @@ import 'dart:ffi'; import 'bindings/libgit2_bindings.dart'; import 'bindings/oid.dart' as bindings; -import 'odb.dart'; +import 'repository.dart'; import 'util.dart'; class Oid { @@ -11,24 +11,26 @@ class Oid { libgit2.git_libgit2_init(); } - /// Initializes a new instance of [Oid] class from provided - /// hexadecimal [sha] string. + /// Initializes a new instance of [Oid] class by determining if an object can be found + /// in the ODB of [repository] with provided hexadecimal [sha] string that is 40 characters + /// long or shorter. /// /// Throws a [LibGit2Error] if error occured. - Oid.fromSHA(String sha) { + Oid.fromSHA(Repository repository, String sha) { libgit2.git_libgit2_init(); - - _oidPointer = bindings.fromSHA(sha); + if (sha.length == 40) { + _oidPointer = bindings.fromSHA(sha); + } else { + final odb = repository.odb; + _oidPointer = odb.existsPrefix(bindings.fromStrN(sha), sha.length); + odb.free(); + } } - /// Initializes a new instance of [Oid] class by determining if an object can be found - /// in the object database of repository with provided hexadecimal [sha] string that is - /// lesser than 40 characters long and [Odb] object. - /// - /// Throws a [LibGit2Error] if error occured. - Oid.fromShortSHA(String sha, Odb odb) { + /// Initializes a new instance of [Oid] class from provided raw git_oid. + Oid.fromRaw(git_oid raw) { libgit2.git_libgit2_init(); - _oidPointer = odb.existsPrefix(bindings.fromStrN(sha), sha.length); + _oidPointer = bindings.fromRaw(raw.id); } late final Pointer _oidPointer; diff --git a/lib/src/reference.dart b/lib/src/reference.dart index 4b2d71d..3e5bbb3 100644 --- a/lib/src/reference.dart +++ b/lib/src/reference.dart @@ -1,11 +1,10 @@ import 'dart:ffi'; import 'bindings/libgit2_bindings.dart'; import 'bindings/reference.dart' as bindings; -import 'bindings/repository.dart' as repo_bindings; -import 'odb.dart'; import 'oid.dart'; import 'reflog.dart'; import 'enums.dart'; +import 'repository.dart'; import 'util.dart'; class References { @@ -139,13 +138,8 @@ class Reference { late final Oid oid; if (isValidShaHex(target)) { - if (target.length == 40) { - oid = Oid.fromSHA(target); - } else { - final odb = Odb(repo_bindings.odb(owner)); - oid = Oid.fromShortSHA(target, odb); - odb.free(); - } + final repo = Repository(bindings.owner(_refPointer)); + oid = Oid.fromSHA(repo, target); } else { final ref = Reference( _repoPointer, @@ -233,6 +227,5 @@ class Reference { /// Releases memory allocated for reference object. void free() { bindings.free(_refPointer); - libgit2.git_libgit2_shutdown(); } } diff --git a/lib/src/reflog.dart b/lib/src/reflog.dart index 3eba9aa..be609ca 100644 --- a/lib/src/reflog.dart +++ b/lib/src/reflog.dart @@ -45,7 +45,6 @@ class RefLog { /// Releases memory allocated for reflog object. void free() { bindings.free(_reflogPointer); - libgit2.git_libgit2_shutdown(); } } diff --git a/lib/src/repository.dart b/lib/src/repository.dart index 63fed51..45169ba 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -10,6 +10,14 @@ import 'bindings/repository.dart' as bindings; import 'util.dart'; class Repository { + /// Initializes a new instance of the [Repository] class from provided + /// pointer to repository object in memory. + /// + /// Should be freed with `free()` to release allocated memory. + Repository(this._repoPointer) { + libgit2.git_libgit2_init(); + } + /// Initializes a new instance of the [Repository] class by creating a new /// Git repository in the given folder. /// @@ -119,13 +127,7 @@ class Repository { late final Oid oid; if (isValidShaHex(target)) { - if (target.length == 40) { - oid = Oid.fromSHA(target); - } else { - final odb = this.odb; - oid = Oid.fromShortSHA(target, odb); - odb.free(); - } + oid = Oid.fromSHA(this, target); bindings.setHeadDetached(_repoPointer, oid.pointer); } else { bindings.setHead(_repoPointer, target); @@ -208,7 +210,6 @@ class Repository { /// Releases memory allocated for repository object. void free() { bindings.free(_repoPointer); - libgit2.git_libgit2_shutdown(); } /// Returns the configuration file for this repository. @@ -269,7 +270,7 @@ class Repository { oid = target as Oid; isDirect = true; } else if (isValidShaHex(target as String)) { - oid = _getOid(target); + oid = Oid.fromSHA(this, target); isDirect = true; } else { isDirect = false; @@ -313,24 +314,10 @@ class Repository { late final Oid oid; if (isValidShaHex(sha)) { - oid = _getOid(sha); + oid = Oid.fromSHA(this, sha); } else { throw ArgumentError.value('$sha is not a valid sha hex string'); } return Commit.lookup(_repoPointer, oid.pointer); } - - /// Returns [Oid] for provided sha hex that is 40 characters long or less. - Oid _getOid(String sha) { - late final Oid oid; - - if (sha.length == 40) { - oid = Oid.fromSHA(sha); - } else { - final odb = this.odb; - oid = Oid.fromShortSHA(sha, odb); - odb.free(); - } - return oid; - } } diff --git a/lib/src/signature.dart b/lib/src/signature.dart index 1aefb3d..1f23717 100644 --- a/lib/src/signature.dart +++ b/lib/src/signature.dart @@ -68,6 +68,5 @@ class Signature { /// Releases memory allocated for signature object. void free() { bindings.free(_signaturePointer); - libgit2.git_libgit2_shutdown(); } } diff --git a/lib/src/tree.dart b/lib/src/tree.dart index 12753ea..fcac52f 100644 --- a/lib/src/tree.dart +++ b/lib/src/tree.dart @@ -27,6 +27,5 @@ class Tree { /// Releases memory allocated for tree object. void free() { bindings.free(_treePointer); - libgit2.git_libgit2_shutdown(); } } diff --git a/test/commit_test.dart b/test/commit_test.dart index 9e3bebf..14ec5f6 100644 --- a/test/commit_test.dart +++ b/test/commit_test.dart @@ -11,6 +11,11 @@ void main() { late Repository repo; final tmpDir = '${Directory.systemTemp.path}/commit_testrepo/'; + const message = "Commit message.\n\nSome description.\n"; + const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628'; + late Signature author; + late Signature commiter; + setUp(() async { if (await Directory(tmpDir).exists()) { await Directory(tmpDir).delete(recursive: true); @@ -20,152 +25,135 @@ void main() { to: await Directory(tmpDir).create(), ); repo = Repository.open(tmpDir); + author = Signature.create( + name: 'Author Name', + email: 'author@email.com', + time: 123, + ); + commiter = Signature.create( + name: 'Commiter', + email: 'commiter@email.com', + time: 124, + ); }); tearDown(() async { + author.free(); + commiter.free(); repo.free(); await Directory(tmpDir).delete(recursive: true); }); - group('lookup', () { - test('successful when 40 char sha hex is provided', () { - final commit = repo[mergeCommit]; - expect(commit, isA()); - commit.free(); - }); - - test('successful when sha hex is short', () { - final commit = repo[mergeCommit.substring(0, 5)]; - expect(commit, isA()); - commit.free(); - }); - - test('throws when provided sha hex is invalid', () { - expect(() => repo['invalid'], throwsA(isA())); - }); - - test('throws when nothing found', () { - expect(() => repo['970ae5c'], throwsA(isA())); - }); - - test('returns with correct fields', () { - final signature = Signature.create( - name: 'Aleksey Kulikov', - email: 'skinny.mind@gmail.com', - time: 1626091184, - offset: 180, - ); - - final commit = repo[mergeCommit]; - final parents = commit.parents; - - expect(commit.messageEncoding, 'utf-8'); - expect(commit.message, 'Merge branch \'feature\'\n'); - expect(commit.id.sha, mergeCommit); - expect(parents.length, 2); - expect( - parents[0].id.sha, - 'c68ff54aabf660fcdd9a2838d401583fe31249e3', - ); - expect(commit.time, 1626091184); - expect(commit.committer, signature); - expect(commit.author, signature); - expect(commit.tree.sha, '7796359a96eb722939c24bafdb1afe9f07f2f628'); - - for (var p in parents) { - p.free(); - } - signature.free(); - commit.free(); - }); + test('successfully returns when 40 char sha hex is provided', () { + final commit = repo[mergeCommit]; + expect(commit, isA()); + commit.free(); }); - group('.create()', () { - test('successfuly creates commit', () { - const message = "Commit message.\n\nSome description.\n"; - const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628'; - final author = Signature.create( - name: 'Author Name', - email: 'author@email.com', - time: 123, - ); - final commiter = Signature.create( - name: 'Commiter', - email: 'commiter@email.com', - time: 124, - ); + test('successfully returns when sha hex is short', () { + final commit = repo[mergeCommit.substring(0, 5)]; + expect(commit, isA()); + commit.free(); + }); - final oid = Commit.create( - repo: repo, - message: message, - author: author, - commiter: commiter, - treeSHA: tree, - parentsSHA: [mergeCommit], - ); + test('successfully creates commit', () { + final oid = Commit.create( + repo: repo, + message: message, + author: author, + commiter: commiter, + treeSHA: tree, + parents: [mergeCommit], + ); - final commit = repo[oid.sha]; - final parents = commit.parents; + final commit = repo[oid.sha]; - expect(commit.id.sha, oid.sha); - expect(commit.message, message); - expect(commit.author, author); - expect(commit.committer, commiter); - expect(commit.time, 124); - expect(commit.tree.sha, tree); - expect(parents.length, 1); - expect(parents[0].id.sha, mergeCommit); + expect(commit.id.sha, oid.sha); + expect(commit.message, message); + expect(commit.messageEncoding, 'utf-8'); + expect(commit.author, author); + expect(commit.committer, commiter); + expect(commit.time, 124); + expect(commit.tree.sha, tree); + expect(commit.parents.length, 1); + expect(commit.parents[0].sha, mergeCommit); - for (var p in parents) { - p.free(); - } - author.free(); - commiter.free(); - commit.free(); - }); + commit.free(); + }); - test('successfuly creates commit with short sha of tree', () { - const message = "Commit message.\n\nSome description.\n"; - const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628'; - final author = Signature.create( - name: 'Author Name', - email: 'author@email.com', - time: 123, - ); - final commiter = Signature.create( - name: 'Commiter', - email: 'commiter@email.com', - time: 124, - ); + test('successfully creates commit without parents', () { + final oid = Commit.create( + repo: repo, + message: message, + author: author, + commiter: commiter, + treeSHA: tree, + parents: [], + ); - final oid = Commit.create( - repo: repo, - message: message, - author: author, - commiter: commiter, - treeSHA: tree.substring(0, 5), - parentsSHA: [mergeCommit], - ); + final commit = repo[oid.sha]; - final commit = repo[oid.sha]; - final parents = commit.parents; + expect(commit.id.sha, oid.sha); + expect(commit.message, message); + expect(commit.messageEncoding, 'utf-8'); + expect(commit.author, author); + expect(commit.committer, commiter); + expect(commit.time, 124); + expect(commit.tree.sha, tree); + expect(commit.parents.length, 0); - expect(commit.id.sha, oid.sha); - expect(commit.message, message); - expect(commit.author, author); - expect(commit.committer, commiter); - expect(commit.time, 124); - expect(commit.tree.sha, tree); - expect(parents.length, 1); - expect(parents[0].id.sha, mergeCommit); + commit.free(); + }); - for (var p in parents) { - p.free(); - } - author.free(); - commiter.free(); - commit.free(); - }); + test('successfully creates commit with 2 parents', () { + final oid = Commit.create( + repo: repo, + message: message, + author: author, + commiter: commiter, + treeSHA: tree, + parents: [mergeCommit, 'fc38877b2552ab554752d9a77e1f48f738cca79b'], + ); + + final commit = repo[oid.sha]; + + expect(commit.id.sha, oid.sha); + expect(commit.message, message); + expect(commit.messageEncoding, 'utf-8'); + expect(commit.author, author); + expect(commit.committer, commiter); + expect(commit.time, 124); + expect(commit.tree.sha, tree); + expect(commit.parents.length, 2); + expect(commit.parents[0].sha, mergeCommit); + expect(commit.parents[1].sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b'); + + commit.free(); + }); + + test('successfully creates commit with short sha of tree', () { + final oid = Commit.create( + repo: repo, + message: message, + author: author, + commiter: commiter, + treeSHA: tree.substring(0, 5), + parents: [mergeCommit], + ); + + final commit = repo[oid.sha]; + + expect(commit.id.sha, oid.sha); + expect(commit.message, message); + expect(commit.messageEncoding, 'utf-8'); + expect(commit.author, author); + expect(commit.committer, commiter); + expect(commit.time, 124); + expect(commit.tree.sha, tree); + expect(commit.parents.length, 1); + expect(commit.parents[0].sha, mergeCommit); + + commit.free(); }); }); } diff --git a/test/odb_test.dart b/test/odb_test.dart index 91e93d9..9b92268 100644 --- a/test/odb_test.dart +++ b/test/odb_test.dart @@ -33,11 +33,8 @@ void main() { }); test('finds object by short oid', () { - final shortSha = '78b8bf'; - final odb = repo.odb; - final oid = Oid.fromShortSHA(shortSha, odb); + final oid = Oid.fromSHA(repo, lastCommit.substring(0, 5)); expect(oid.sha, lastCommit); - odb.free(); }); }); } diff --git a/test/oid_test.dart b/test/oid_test.dart index f6b6e7d..d9ffa59 100644 --- a/test/oid_test.dart +++ b/test/oid_test.dart @@ -1,5 +1,5 @@ import 'dart:io'; - +import 'dart:ffi'; import 'package:test/test.dart'; import 'package:libgit2dart/libgit2dart.dart'; import 'helpers/util.dart'; @@ -30,46 +30,50 @@ void main() { }); group('fromSHA()', () { test('initializes successfully', () { - final oid = Oid.fromSHA(sha); + final oid = Oid.fromSHA(repo, sha); + expect(oid, isA()); + expect(oid.sha, sha); + }); + + test('initializes successfully from short hex string', () { + final oid = Oid.fromSHA(repo, sha.substring(0, 5)); + expect(oid, isA()); expect(oid.sha, sha); }); }); - group('fromShortSHA()', () { - test('initializes successfully from short hex string', () { - final odb = repo.odb; - final oid = Oid.fromShortSHA(sha.substring(0, 5), odb); - + group('fromRaw()', () { + test('initializes successfully', () { + final sourceOid = Oid.fromSHA(repo, sha); + final oid = Oid.fromRaw(sourceOid.pointer.ref); expect(oid, isA()); expect(oid.sha, sha); - - odb.free(); }); }); test('returns sha hex string', () { - final oid = Oid.fromSHA(sha); + final oid = Oid.fromSHA(repo, sha); expect(oid.sha, equals(sha)); }); group('compare', () { test('< and <=', () { - final oid1 = Oid.fromSHA(sha); - final oid2 = Oid.fromSHA(biggerSha); + final oid1 = Oid.fromSHA(repo, sha); + final oid2 = Oid.fromSHA(repo, biggerSha); expect(oid1 < oid2, true); expect(oid1 <= oid2, true); }); test('==', () { - final oid1 = Oid.fromSHA(sha); - final oid2 = Oid.fromSHA(sha); + final oid1 = Oid.fromSHA(repo, sha); + final oid2 = Oid.fromSHA(repo, sha); expect(oid1 == oid2, true); }); test('> and >=', () { - final oid1 = Oid.fromSHA(sha); - final oid2 = Oid.fromSHA(lesserSha); + final oid1 = Oid.fromSHA(repo, sha); + final oid2 = Oid.fromSHA(repo, lesserSha); expect(oid1 > oid2, true); expect(oid1 >= oid2, true); });