From c2da51af941e8eca0edb54b516ce7ccf1c54585e Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Tue, 2 Nov 2021 18:00:15 +0300 Subject: [PATCH] feat(commit): make 'updateRef' to be required argument --- lib/src/bindings/commit.dart | 4 ++-- lib/src/commit.dart | 4 ++-- lib/src/repository.dart | 12 +++++++----- test/commit_test.dart | 27 ++++++++++++++++----------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/src/bindings/commit.dart b/lib/src/bindings/commit.dart index b9bdeff..a139e95 100644 --- a/lib/src/bindings/commit.dart +++ b/lib/src/bindings/commit.dart @@ -65,7 +65,7 @@ void annotatedFree(Pointer commit) { /// Throws a [LibGit2Error] if error occured. Pointer create({ required Pointer repoPointer, - String? updateRef, + required String updateRef, required Pointer authorPointer, required Pointer committerPointer, String? messageEncoding, @@ -75,7 +75,7 @@ Pointer create({ required List> parents, }) { final out = calloc(); - final updateRefC = updateRef?.toNativeUtf8().cast() ?? nullptr; + final updateRefC = updateRef.toNativeUtf8().cast(); final messageEncodingC = messageEncoding?.toNativeUtf8().cast() ?? nullptr; final messageC = message.toNativeUtf8().cast(); diff --git a/lib/src/commit.dart b/lib/src/commit.dart index 56336fa..c69944a 100644 --- a/lib/src/commit.dart +++ b/lib/src/commit.dart @@ -58,7 +58,7 @@ class Commit { /// Throws a [LibGit2Error] if error occured. static Oid create({ required Repository repo, - String? updateRef, + required String updateRef, required Signature author, required Signature committer, String? messageEncoding, @@ -103,10 +103,10 @@ class Commit { static Oid amend({ required Repository repo, required Commit commit, + required String? updateRef, Signature? author, Signature? committer, Tree? tree, - String? updateRef, String? message, String? messageEncoding, }) { diff --git a/lib/src/repository.dart b/lib/src/repository.dart index 8800eda..93558eb 100644 --- a/lib/src/repository.dart +++ b/lib/src/repository.dart @@ -558,8 +558,8 @@ class Repository { /// this commit. If the reference is not direct, it will be resolved to a /// direct reference. Use "HEAD" to update the HEAD of the current branch and /// make it point to this commit. If the reference doesn't exist yet, it will - /// be created. If it does exist, the first parent - /// must be the tip of this branch. + /// be created. If it does exist, the first parent must be the tip of this + /// branch. /// /// [author] is the signature with author and author time of commit. /// @@ -580,21 +580,23 @@ class Repository { /// /// Throws a [LibGit2Error] if error occured. Oid createCommit({ + required String updateRef, required String message, required Signature author, required Signature commiter, required Tree tree, required List parents, - String? updateRef, String? messageEncoding, }) { return Commit.create( repo: this, + updateRef: updateRef, message: message, author: author, committer: commiter, tree: tree, parents: parents, + messageEncoding: messageEncoding, ); } @@ -619,20 +621,20 @@ class Repository { /// Throws a [LibGit2Error] if error occured. Oid amendCommit({ required Commit commit, + required String? updateRef, Signature? author, Signature? committer, Tree? tree, - String? updateRef, String? message, String? messageEncoding, }) { return Commit.amend( repo: this, commit: commit, + updateRef: updateRef, author: author, committer: committer, tree: tree, - updateRef: updateRef, message: message, messageEncoding: messageEncoding, ); diff --git a/test/commit_test.dart b/test/commit_test.dart index 9ecae5f..47c7f4b 100644 --- a/test/commit_test.dart +++ b/test/commit_test.dart @@ -12,7 +12,7 @@ void main() { late Signature author; late Signature commiter; late Tree tree; - late Oid mergeCommit; + late Oid tip; const message = "Commit message.\n\nSome description.\n"; setUp(() { @@ -28,10 +28,10 @@ void main() { email: 'commiter@email.com', time: 124, ); - mergeCommit = repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8']; + tip = repo['821ed6e80627b8769d170a293862f9fc60825226']; tree = Tree.lookup( repo: repo, - oid: repo['7796359a96eb722939c24bafdb1afe9f07f2f628'], + oid: repo['a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f'], ); }); @@ -45,7 +45,7 @@ void main() { group('Commit', () { test('successfully lookups for provided oid', () { - final commit = repo.lookupCommit(mergeCommit); + final commit = repo.lookupCommit(tip); expect(commit, isA()); commit.free(); }); @@ -58,7 +58,7 @@ void main() { }); test('successfully lookups annotated commit for provided oid', () { - final annotated = AnnotatedCommit.lookup(repo: repo, oid: mergeCommit); + final annotated = AnnotatedCommit.lookup(repo: repo, oid: tip); expect(annotated, isA()); annotated.free(); }); @@ -101,8 +101,9 @@ void main() { }); test('successfully creates commit', () { - final parent = repo.lookupCommit(mergeCommit); + final parent = repo.lookupCommit(tip); final oid = repo.createCommit( + updateRef: 'HEAD', message: message, author: author, commiter: commiter, @@ -120,7 +121,7 @@ void main() { expect(commit.time, 124); expect(commit.tree.oid, tree.oid); expect(commit.parents.length, 1); - expect(commit.parents[0], mergeCommit); + expect(commit.parents[0], tip); commit.free(); parent.free(); @@ -128,6 +129,7 @@ void main() { test('successfully creates commit without parents', () { final oid = repo.createCommit( + updateRef: 'refs/heads/new', message: message, author: author, commiter: commiter, @@ -150,12 +152,13 @@ void main() { }); test('successfully creates commit with 2 parents', () { - final parent1 = repo.lookupCommit(mergeCommit); + final parent1 = repo.lookupCommit(tip); final parent2 = repo.lookupCommit( repo['fc38877b2552ab554752d9a77e1f48f738cca79b'], ); final oid = Commit.create( + updateRef: 'HEAD', repo: repo, message: message, author: author, @@ -174,7 +177,7 @@ void main() { expect(commit.time, 124); expect(commit.tree.oid, tree.oid); expect(commit.parents.length, 2); - expect(commit.parents[0], mergeCommit); + expect(commit.parents[0], tip); expect(commit.parents[1], parent2.oid); parent1.free(); @@ -183,11 +186,12 @@ void main() { }); test('throws when trying to create commit and error occurs', () { - final parent = repo.lookupCommit(mergeCommit); + final parent = repo.lookupCommit(tip); final nullRepo = Repository(nullptr); expect( () => nullRepo.createCommit( + updateRef: 'HEAD', message: message, author: author, commiter: commiter, @@ -262,6 +266,7 @@ void main() { expect( () => repo.amendCommit( + updateRef: null, commit: commit, message: 'amended commit\n', ), @@ -293,7 +298,7 @@ void main() { }); test('returns string representation of Commit object', () { - final commit = repo.lookupCommit(mergeCommit); + final commit = repo.lookupCommit(tip); expect(commit.toString(), contains('Commit{')); commit.free(); });