From 28f08e308a06448f4cecab140681b110ecf3af23 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Thu, 21 Apr 2022 19:46:19 +0300 Subject: [PATCH] test: remove unnecessary variables declarations --- test/annotated_test.dart | 5 +- test/branch_test.dart | 76 +++++++------- test/checkout_test.dart | 22 ++-- test/commit_test.dart | 39 ++++--- test/describe_test.dart | 32 +++--- test/diff_test.dart | 107 ++++++++++--------- test/index_test.dart | 126 +++++++++++------------ test/merge_test.dart | 199 ++++++++++++++++-------------------- test/note_test.dart | 6 +- test/odb_test.dart | 5 +- test/packbuilder_test.dart | 20 ++-- test/patch_test.dart | 15 +-- test/rebase_test.dart | 66 +++++------- test/reference_test.dart | 54 +++++----- test/remote_prune_test.dart | 3 - test/remote_test.dart | 49 +++------ test/repository_test.dart | 6 +- test/reset_test.dart | 18 ++-- test/revwalk_test.dart | 29 ++---- test/submodule_test.dart | 7 +- test/tag_test.dart | 18 ++-- test/treebuilder_test.dart | 3 +- test/worktree_test.dart | 3 +- 23 files changed, 416 insertions(+), 492 deletions(-) diff --git a/test/annotated_test.dart b/test/annotated_test.dart index b40d2bf..78a4d8b 100644 --- a/test/annotated_test.dart +++ b/test/annotated_test.dart @@ -39,14 +39,15 @@ void main() { }); test('creates annotated commit from provided reference', () { - final reference = Reference.lookup(repo: repo, name: 'refs/heads/master'); + const refName = 'refs/heads/master'; + final reference = Reference.lookup(repo: repo, name: refName); final annotated = AnnotatedCommit.fromReference( repo: repo, reference: reference, ); expect(annotated.oid, reference.target); - expect(annotated.refName, 'refs/heads/master'); + expect(annotated.refName, refName); }); test( diff --git a/test/branch_test.dart b/test/branch_test.dart index 31fc2c7..5c0aafa 100644 --- a/test/branch_test.dart +++ b/test/branch_test.dart @@ -88,11 +88,8 @@ void main() { }); test('checks if branch is current head', () { - final masterBranch = Branch.lookup(repo: repo, name: 'master'); - final featureBranch = Branch.lookup(repo: repo, name: 'feature'); - - expect(masterBranch.isHead, true); - expect(featureBranch.isHead, false); + expect(Branch.lookup(repo: repo, name: 'master').isHead, true); + expect(Branch.lookup(repo: repo, name: 'feature').isHead, false); }); test('throws when checking if branch is current head and error occurs', () { @@ -103,11 +100,8 @@ void main() { }); test('checks if branch is checked out', () { - final masterBranch = Branch.lookup(repo: repo, name: 'master'); - final featureBranch = Branch.lookup(repo: repo, name: 'feature'); - - expect(masterBranch.isCheckedOut, true); - expect(featureBranch.isCheckedOut, false); + expect(Branch.lookup(repo: repo, name: 'master').isCheckedOut, true); + expect(Branch.lookup(repo: repo, name: 'feature').isCheckedOut, false); }); test('throws when checking if branch is checked out and error occurs', () { @@ -118,8 +112,7 @@ void main() { }); test('returns name', () { - final branch = Branch.lookup(repo: repo, name: 'master'); - expect(branch.name, 'master'); + expect(Branch.lookup(repo: repo, name: 'master').name, 'master'); }); test('throws when getting name and error occurs', () { @@ -134,13 +127,14 @@ void main() { test( 'throws when getting remote name of a remote-tracking branch and ' 'error occurs', () { - final branch = Branch.lookup(repo: repo, name: 'master'); - expect(() => branch.remoteName, throwsA(isA())); + expect( + () => Branch.lookup(repo: repo, name: 'master').remoteName, + throwsA(isA()), + ); }); test('returns upstream of a local branch', () { - final branch = Branch.lookup(repo: repo, name: 'master'); - final upstream = branch.upstream; + final upstream = Branch.lookup(repo: repo, name: 'master').upstream; expect(upstream.isRemote, true); expect(upstream.name, 'refs/remotes/origin/master'); @@ -182,29 +176,41 @@ void main() { }); test('returns upstream name of a local branch', () { - final branch = Branch.lookup(repo: repo, name: 'master'); - expect(branch.upstreamName, 'refs/remotes/origin/master'); + expect( + Branch.lookup(repo: repo, name: 'master').upstreamName, + 'refs/remotes/origin/master', + ); }); test('throws when trying to get upstream name of a branch and error occurs', () { - final branch = Branch.lookup(repo: repo, name: 'feature'); - expect(() => branch.upstreamName, throwsA(isA())); + expect( + () => Branch.lookup(repo: repo, name: 'feature').upstreamName, + throwsA(isA()), + ); }); test('returns upstream remote of a local branch', () { - final branch = Branch.lookup(repo: repo, name: 'master'); - expect(branch.upstreamRemote, 'origin'); + expect( + Branch.lookup(repo: repo, name: 'master').upstreamRemote, + 'origin', + ); }); test('throws when trying to get upstream remote of a remote branch', () { - final branch = Branch.list(repo: repo, type: GitBranch.remote).first; - expect(() => branch.upstreamRemote, throwsA(isA())); + expect( + () => Branch.list(repo: repo, type: GitBranch.remote) + .first + .upstreamRemote, + throwsA(isA()), + ); }); test('returns upstream merge of a local branch', () { - final branch = Branch.lookup(repo: repo, name: 'master'); - expect(branch.upstreamMerge, 'refs/heads/master'); + expect( + Branch.lookup(repo: repo, name: 'master').upstreamMerge, + 'refs/heads/master', + ); }); test('throws when trying to get upstream merge of a remote branch', () { @@ -219,9 +225,8 @@ void main() { name: 'testing', target: Commit.lookup(repo: repo, oid: lastCommit), ); - final branches = Branch.list(repo: repo); - expect(branches.length, 4); + expect(Branch.list(repo: repo).length, 4); expect(branch.target, lastCommit); }); @@ -241,9 +246,8 @@ void main() { target: Commit.lookup(repo: repo, oid: lastCommit), force: true, ); - final localBranches = Branch.list(repo: repo, type: GitBranch.local); - expect(localBranches.length, 2); + expect(Branch.list(repo: repo, type: GitBranch.local).length, 2); expect(branch.target, lastCommit); }); }); @@ -269,15 +273,16 @@ void main() { group('rename()', () { test('renames branch', () { Branch.rename(repo: repo, oldName: 'feature', newName: 'renamed'); - final branch = Branch.lookup(repo: repo, name: 'renamed'); - final branches = Branch.list(repo: repo); - expect(branches.length, 3); + expect(Branch.list(repo: repo).length, 3); expect( () => Branch.lookup(repo: repo, name: 'feature'), throwsA(isA()), ); - expect(branch.target, featureCommit); + expect( + Branch.lookup(repo: repo, name: 'renamed').target, + featureCommit, + ); }); test('throws when name already exists', () { @@ -298,9 +303,8 @@ void main() { newName: 'feature', force: true, ); - final branch = Branch.lookup(repo: repo, name: 'feature'); - expect(branch.target, lastCommit); + expect(Branch.lookup(repo: repo, name: 'feature').target, lastCommit); }); test('throws when name is invalid', () { diff --git a/test/checkout_test.dart b/test/checkout_test.dart index 3963c41..7029b9f 100644 --- a/test/checkout_test.dart +++ b/test/checkout_test.dart @@ -72,8 +72,7 @@ void main() { }); test('checkouts reference', () { - final masterHead = Commit.lookup(repo: repo, oid: repo['821ed6e']); - final masterTree = masterHead.tree; + final masterTree = Commit.lookup(repo: repo, oid: repo['821ed6e']).tree; expect( masterTree.entries.any((e) => e.name == 'another_feature_file'), false, @@ -82,9 +81,8 @@ void main() { Checkout.reference(repo: repo, name: 'refs/heads/feature'); final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']); final featureTree = featureHead.tree; - final repoHead = repo.head; // does not change HEAD - expect(repoHead.target, isNot(featureHead.oid)); + expect(repo.head.target, isNot(featureHead.oid)); expect( featureTree.entries.any((e) => e.name == 'another_feature_file'), true, @@ -105,16 +103,14 @@ void main() { }); test('checkouts commit', () { - final index = repo.index; - expect(index.find('another_feature_file'), equals(false)); + expect(repo.index.find('another_feature_file'), equals(false)); final featureHead = Commit.lookup(repo: repo, oid: repo['5aecfa0']); Checkout.commit(repo: repo, commit: featureHead); - final repoHead = repo.head; // does not change HEAD - expect(repoHead.target, isNot(featureHead.oid)); - expect(index.find('another_feature_file'), equals(true)); + expect(repo.head.target, isNot(featureHead.oid)); + expect(repo.index.find('another_feature_file'), equals(true)); }); test('checkouts commit with provided path', () { @@ -125,9 +121,8 @@ void main() { paths: ['another_feature_file'], ); - final repoHead = repo.head; // does not change HEAD - expect(repoHead.target, isNot(featureHead.oid)); + expect(repo.head.target, isNot(featureHead.oid)); expect( repo.status, { @@ -191,8 +186,7 @@ void main() { }); test('performs dry run checkout', () { - final index = repo.index; - expect(index.length, 4); + expect(repo.index.length, 4); final file = File(p.join(repo.workdir, 'another_feature_file')); expect(file.existsSync(), false); @@ -201,7 +195,7 @@ void main() { name: 'refs/heads/feature', strategy: {GitCheckout.dryRun}, ); - expect(index.length, 4); + expect(repo.index.length, 4); expect(file.existsSync(), false); }); }); diff --git a/test/commit_test.dart b/test/commit_test.dart index e309def..7222b68 100644 --- a/test/commit_test.dart +++ b/test/commit_test.dart @@ -58,14 +58,13 @@ void main() { test('reverts commit affecting index and workdir', () { final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']); - final index = repo.index; final file = File(p.join(repo.workdir, 'dir', 'dir_file.txt')); - expect(index.find('dir/dir_file.txt'), true); + expect(repo.index.find('dir/dir_file.txt'), true); expect(file.existsSync(), true); commit.revert(); - expect(index.find('dir/dir_file.txt'), false); + expect(repo.index.find('dir/dir_file.txt'), false); expect(file.existsSync(), false); }); @@ -74,14 +73,14 @@ void main() { }); test('reverts commit to provided commit', () { - final to = Commit.lookup(repo: repo, oid: repo['78b8bf1']); - final from = Commit.lookup(repo: repo, oid: repo['821ed6e']); - final index = repo.index; final file = File(p.join(repo.workdir, 'dir', 'dir_file.txt')); - expect(index.find('dir/dir_file.txt'), true); + expect(repo.index.find('dir/dir_file.txt'), true); expect(file.existsSync(), true); - final revertIndex = from.revertTo(commit: to); + final from = Commit.lookup(repo: repo, oid: repo['821ed6e']); + final revertIndex = from.revertTo( + commit: Commit.lookup(repo: repo, oid: repo['78b8bf1']), + ); expect(revertIndex.find('dir/dir_file.txt'), false); expect(file.existsSync(), true); }); @@ -104,7 +103,6 @@ void main() { }); test('creates commit', () { - final parent = Commit.lookup(repo: repo, oid: tip); final oid = Commit.create( repo: repo, updateRef: 'HEAD', @@ -112,7 +110,7 @@ void main() { author: author, committer: committer, tree: tree, - parents: [parent], + parents: [Commit.lookup(repo: repo, oid: tip)], ); final commit = Commit.lookup(repo: repo, oid: oid); @@ -157,7 +155,6 @@ Some description. }); test('writes commit into the buffer', () { - final parent = Commit.lookup(repo: repo, oid: tip); final commit = Commit.createBuffer( repo: repo, updateRef: 'HEAD', @@ -165,7 +162,7 @@ Some description. author: author, committer: committer, tree: tree, - parents: [parent], + parents: [Commit.lookup(repo: repo, oid: tip)], ); const expected = """ @@ -229,7 +226,7 @@ Some description. expect(commit.time, 124); expect(commit.treeOid, tree.oid); expect(commit.parents.length, 2); - expect(commit.parents[0], tip); + expect(commit.parents[0], parent1.oid); expect(commit.parents[1], parent2.oid); }); @@ -363,16 +360,16 @@ Some description. }); test('returns nth generation ancestor commit', () { - final commit = Commit.lookup(repo: repo, oid: tip); - final ancestor = commit.nthGenAncestor(3); - + final ancestor = Commit.lookup(repo: repo, oid: tip).nthGenAncestor(3); expect(ancestor.oid.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521'); }); test('throws when trying to get nth generation ancestor and none exists', () { - final commit = Commit.lookup(repo: repo, oid: tip); - expect(() => commit.nthGenAncestor(10), throwsA(isA())); + expect( + () => Commit.lookup(repo: repo, oid: tip).nthGenAncestor(10), + throwsA(isA()), + ); }); test('returns parent at specified position', () { @@ -385,8 +382,10 @@ Some description. }); test('throws when trying to get the parent at invalid position', () { - final commit = Commit.lookup(repo: repo, oid: tip); - expect(() => commit.parent(10), throwsA(isA())); + expect( + () => Commit.lookup(repo: repo, oid: tip).parent(10), + throwsA(isA()), + ); }); test('manually releases allocated memory', () { diff --git a/test/describe_test.dart b/test/describe_test.dart index 05c798c..6a6f267 100644 --- a/test/describe_test.dart +++ b/test/describe_test.dart @@ -27,8 +27,10 @@ void main() { }); test('throws when trying to describe and error occurs', () { - final nullRepo = Repository(nullptr); - expect(() => nullRepo.describe(), throwsA(isA())); + expect( + () => Repository(nullptr).describe(), + throwsA(isA()), + ); }); test('describes commit', () { @@ -41,23 +43,28 @@ void main() { }); test('throws when trying to describe and no reference found', () { - final commit = Commit.lookup(repo: repo, oid: repo['f17d0d4']); - expect(() => repo.describe(commit: commit), throwsA(isA())); + expect( + () => repo.describe( + commit: Commit.lookup(repo: repo, oid: repo['f17d0d4']), + ), + throwsA(isA()), + ); }); test('returns oid when fallback argument is provided', () { - final commit = Commit.lookup(repo: repo, oid: repo['f17d0d4']); expect( - repo.describe(commit: commit, showCommitOidAsFallback: true), + repo.describe( + commit: Commit.lookup(repo: repo, oid: repo['f17d0d4']), + showCommitOidAsFallback: true, + ), 'f17d0d4', ); }); test('describes with provided strategy', () { - final commit = Commit.lookup(repo: repo, oid: repo['5aecfa0']); expect( repo.describe( - commit: commit, + commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']), describeStrategy: GitDescribeStrategy.all, ), 'heads/feature', @@ -70,7 +77,6 @@ void main() { email: 'author@email.com', time: 1234, ); - final commit = Commit.lookup(repo: repo, oid: repo['fc38877']); Tag.createAnnotated( repo: repo, tagName: 'test/tag1', @@ -81,18 +87,20 @@ void main() { ); expect( - repo.describe(commit: commit, pattern: 'test/*'), + repo.describe( + commit: Commit.lookup(repo: repo, oid: repo['fc38877']), + pattern: 'test/*', + ), 'test/tag1-2-gfc38877', ); }); test('describes and follows first parent only', () { - final commit = Commit.lookup(repo: repo, oid: repo['821ed6e']); Tag.delete(repo: repo, name: 'v0.2'); expect( repo.describe( - commit: commit, + commit: Commit.lookup(repo: repo, oid: repo['821ed6e']), onlyFollowFirstParent: true, describeStrategy: GitDescribeStrategy.tags, ), diff --git a/test/diff_test.dart b/test/diff_test.dart index 463a030..754b74e 100644 --- a/test/diff_test.dart +++ b/test/diff_test.dart @@ -144,10 +144,9 @@ index e69de29..c217c63 100644 }); test('returns diff between index and tree', () { - final commit = Commit.lookup(repo: repo, oid: repo.head.target); final diff = Diff.treeToIndex( repo: repo, - tree: commit.tree, + tree: Commit.lookup(repo: repo, oid: repo.head.target).tree, index: repo.index, ); @@ -167,8 +166,10 @@ index e69de29..c217c63 100644 }); test('returns diff between tree and workdir', () { - final commit = Commit.lookup(repo: repo, oid: repo.head.target); - final diff = Diff.treeToWorkdir(repo: repo, tree: commit.tree); + final diff = Diff.treeToWorkdir( + repo: repo, + tree: Commit.lookup(repo: repo, oid: repo.head.target).tree, + ); expect(diff.length, 9); for (var i = 0; i < diff.deltas.length; i++) { @@ -185,8 +186,10 @@ index e69de29..c217c63 100644 }); test('returns diff between tree and workdir with index', () { - final commit = Commit.lookup(repo: repo, oid: repo.head.target); - final diff = Diff.treeToWorkdirWithIndex(repo: repo, tree: commit.tree); + final diff = Diff.treeToWorkdirWithIndex( + repo: repo, + tree: Commit.lookup(repo: repo, oid: repo.head.target).tree, + ); expect(diff.length, 11); for (var i = 0; i < diff.deltas.length; i++) { @@ -207,12 +210,10 @@ index e69de29..c217c63 100644 }); test('returns diff between tree and tree', () { - final commit = Commit.lookup(repo: repo, oid: repo.head.target); - final newTree = Tree.lookup(repo: repo, oid: repo['b85d53c']); final diff = Diff.treeToTree( repo: repo, - oldTree: commit.tree, - newTree: newTree, + oldTree: Commit.lookup(repo: repo, oid: repo.head.target).tree, + newTree: Tree.lookup(repo: repo, oid: repo['b85d53c']), ); expect(diff.length, 10); @@ -222,10 +223,9 @@ index e69de29..c217c63 100644 }); test('returns diff between tree and empty tree', () { - final commit = Commit.lookup(repo: repo, oid: repo.head.target); final diff = Diff.treeToTree( repo: repo, - oldTree: commit.tree, + oldTree: Commit.lookup(repo: repo, oid: repo.head.target).tree, newTree: null, ); @@ -236,11 +236,10 @@ index e69de29..c217c63 100644 }); test('returns diff between empty tree and tree', () { - final commit = Commit.lookup(repo: repo, oid: repo.head.target); final diff = Diff.treeToTree( repo: repo, oldTree: null, - newTree: commit.tree, + newTree: Commit.lookup(repo: repo, oid: repo.head.target).tree, ); expect(diff.length, 11); @@ -295,11 +294,10 @@ index e69de29..c217c63 100644 test('merges diffs', () { final commit = Commit.lookup(repo: repo, oid: repo.head.target); - final newTree = Tree.lookup(repo: repo, oid: repo['b85d53c']); final diff1 = Diff.treeToTree( repo: repo, oldTree: commit.tree, - newTree: newTree, + newTree: Tree.lookup(repo: repo, oid: repo['b85d53c']), ); final diff2 = Diff.treeToWorkdir(repo: repo, tree: commit.tree); @@ -358,13 +356,12 @@ index e69de29..c217c63 100644 }); test('applies diff to repository', () { - final diff = Diff.parse(patchText); final file = File(p.join(tmpDir.path, 'subdir', 'modified_file')); Checkout.head(repo: repo, strategy: {GitCheckout.force}); expect(file.readAsStringSync(), ''); - diff.apply(repo: repo); + Diff.parse(patchText).apply(repo: repo); expect(file.readAsStringSync(), 'Modified content\n'); }); @@ -396,78 +393,83 @@ index e69de29..c217c63 100644 }); test('does not apply hunk with non existing index', () { - final diff = Diff.parse(patchText); final file = File(p.join(tmpDir.path, 'subdir', 'modified_file')); Checkout.head(repo: repo, strategy: {GitCheckout.force}); expect(file.readAsStringSync(), ''); - diff.apply(repo: repo, hunkIndex: 10); + Diff.parse(patchText).apply(repo: repo, hunkIndex: 10); expect(file.readAsStringSync(), ''); }); test('applies diff to tree', () { Checkout.head(repo: repo, strategy: {GitCheckout.force}); - final oldBlob = Blob.lookup( - repo: repo, - oid: repo.index['subdir/modified_file'].oid, + expect( + Blob.lookup( + repo: repo, + oid: repo.index['subdir/modified_file'].oid, + ).content, + '', ); - expect(oldBlob.content, ''); - final diff = Diff.parse(patchText); - final commit = Commit.lookup(repo: repo, oid: repo.head.target); - - final newIndex = diff.applyToTree(repo: repo, tree: commit.tree); - final newBlob = Blob.lookup( + final newIndex = Diff.parse(patchText).applyToTree( repo: repo, - oid: newIndex['subdir/modified_file'].oid, + tree: Commit.lookup(repo: repo, oid: repo.head.target).tree, + ); + expect( + Blob.lookup( + repo: repo, + oid: newIndex['subdir/modified_file'].oid, + ).content, + 'Modified content\n', ); - expect(newBlob.content, 'Modified content\n'); }); test('applies hunk with provided index to tree', () { Checkout.head(repo: repo, strategy: {GitCheckout.force}); - final oldBlob = Blob.lookup( - repo: repo, - oid: repo.index['subdir/modified_file'].oid, + expect( + Blob.lookup( + repo: repo, + oid: repo.index['subdir/modified_file'].oid, + ).content, + '', ); - expect(oldBlob.content, ''); final diff = Diff.parse(patchText); final hunk = diff.patches.first.hunks.first; - final commit = Commit.lookup(repo: repo, oid: repo.head.target); final newIndex = diff.applyToTree( repo: repo, - tree: commit.tree, + tree: Commit.lookup(repo: repo, oid: repo.head.target).tree, hunkIndex: hunk.index, ); - final newBlob = Blob.lookup( - repo: repo, - oid: newIndex['subdir/modified_file'].oid, + expect( + Blob.lookup( + repo: repo, + oid: newIndex['subdir/modified_file'].oid, + ).content, + 'Modified content\n', ); - expect(newBlob.content, 'Modified content\n'); }); test('throws when trying to apply diff to tree and error occurs', () { - final diff = Diff.parse(patchText); expect( - () => diff.applyToTree(repo: repo, tree: Tree(nullptr)), + () => Diff.parse(patchText).applyToTree( + repo: repo, + tree: Tree(nullptr), + ), throwsA(isA()), ); }); }); test('finds similar entries', () { - final commit = Commit.lookup(repo: repo, oid: repo.head.target); - final newTree = Tree.lookup(repo: repo, oid: repo.index.writeTree()); - final diff = Diff.treeToTree( repo: repo, - oldTree: commit.tree, - newTree: newTree, + oldTree: Commit.lookup(repo: repo, oid: repo.head.target).tree, + newTree: Tree.lookup(repo: repo, oid: repo.index.writeTree()), ); expect( diff.deltas.singleWhere((e) => e.newFile.path == 'staged_new').status, @@ -554,13 +556,11 @@ index e69de29..c217c63 100644 }); test('returns patch diff string', () { - final diff = Diff.parse(patchText); - expect(diff.patch, patchText); + expect(Diff.parse(patchText).patch, patchText); }); test('returns hunks in a patch', () { - final diff = Diff.parse(patchText); - final patch = Patch.fromDiff(diff: diff, index: 0); + final patch = Patch.fromDiff(diff: Diff.parse(patchText), index: 0); final hunk = patch.hunks[0]; expect(patch.hunks.length, 1); @@ -573,8 +573,7 @@ index e69de29..c217c63 100644 }); test('returns lines in a hunk', () { - final diff = Diff.parse(patchText); - final patch = Patch.fromDiff(diff: diff, index: 0); + final patch = Patch.fromDiff(diff: Diff.parse(patchText), index: 0); final hunk = patch.hunks[0]; final line = hunk.lines[0]; diff --git a/test/index_test.dart b/test/index_test.dart index 409023d..d6605cc 100644 --- a/test/index_test.dart +++ b/test/index_test.dart @@ -159,10 +159,9 @@ void main() { group('addFromBuffer()', () { test('updates index entry from a buffer', () { - final entry = index['file']; expect(repo.status, isEmpty); - index.addFromBuffer(entry: entry, buffer: 'updated'); + index.addFromBuffer(entry: index['file'], buffer: 'updated'); expect(repo.status, { 'file': {GitStatus.indexModified, GitStatus.wtModified} }); @@ -282,9 +281,8 @@ void main() { }); test('reads tree with provided SHA hex', () { - final tree = Tree.lookup(repo: repo, oid: repo['df2b8fc']); expect(index.length, 4); - index.readTree(tree); + index.readTree(Tree.lookup(repo: repo, oid: repo['df2b8fc'])); expect(index.length, 1); @@ -294,8 +292,7 @@ void main() { }); test('writes tree', () { - final oid = index.writeTree(); - expect(oid.sha, 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f'); + expect(index.writeTree().sha, 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f'); }); test('throws when trying to write tree to invalid repository', () { @@ -309,14 +306,14 @@ void main() { final tmpDir = setupRepo(Directory(mergeRepoPath)); final repo = Repository.open(tmpDir.path); - final conflictBranch = Branch.lookup(repo: repo, name: 'conflict-branch'); - final commit = AnnotatedCommit.lookup( + Merge.commit( repo: repo, - oid: conflictBranch.target, + commit: AnnotatedCommit.lookup( + repo: repo, + oid: Branch.lookup(repo: repo, name: 'conflict-branch').target, + ), ); - Merge.commit(repo: repo, commit: commit); - expect(() => repo.index.writeTree(), throwsA(isA())); repo.free(); @@ -341,19 +338,17 @@ void main() { final repoDir = setupRepo(Directory(mergeRepoPath)); final conflictRepo = Repository.open(repoDir.path); - final conflictBranch = Branch.lookup( - repo: conflictRepo, - name: 'ancestor-conflict', - ); - final commit = AnnotatedCommit.lookup( - repo: conflictRepo, - oid: conflictBranch.target, - ); - Checkout.reference(repo: conflictRepo, name: 'refs/heads/feature'); conflictRepo.setHead('refs/heads/feature'); - Merge.commit(repo: conflictRepo, commit: commit); + Merge.commit( + repo: conflictRepo, + commit: AnnotatedCommit.lookup( + repo: conflictRepo, + oid: Branch.lookup(repo: conflictRepo, name: 'ancestor-conflict') + .target, + ), + ); final conflictedFile = conflictRepo.index.conflicts['feature_file']!; expect(conflictedFile.ancestor?.path, 'feature_file'); @@ -369,16 +364,16 @@ void main() { final repoDir = setupRepo(Directory(mergeRepoPath)); final conflictRepo = Repository.open(repoDir.path); - final conflictBranch = Branch.lookup( + Merge.commit( repo: conflictRepo, - name: 'conflict-branch', + commit: AnnotatedCommit.lookup( + repo: conflictRepo, + oid: Branch.lookup( + repo: conflictRepo, + name: 'conflict-branch', + ).target, + ), ); - final commit = AnnotatedCommit.lookup( - repo: conflictRepo, - oid: conflictBranch.target, - ); - - Merge.commit(repo: conflictRepo, commit: commit); final conflictedFile = conflictRepo.index.conflicts['conflict_file']!; expect(conflictedFile.ancestor?.path, null); @@ -394,19 +389,17 @@ void main() { final repoDir = setupRepo(Directory(mergeRepoPath)); final conflictRepo = Repository.open(repoDir.path); - final conflictBranch = Branch.lookup( - repo: conflictRepo, - name: 'ancestor-conflict', - ); - final commit = AnnotatedCommit.lookup( - repo: conflictRepo, - oid: conflictBranch.target, - ); - Checkout.reference(repo: conflictRepo, name: 'refs/heads/our-conflict'); conflictRepo.setHead('refs/heads/our-conflict'); - Merge.commit(repo: conflictRepo, commit: commit); + Merge.commit( + repo: conflictRepo, + commit: AnnotatedCommit.lookup( + repo: conflictRepo, + oid: Branch.lookup(repo: conflictRepo, name: 'ancestor-conflict') + .target, + ), + ); final conflictedFile = conflictRepo.index.conflicts['feature_file']!; expect(conflictedFile.ancestor?.path, 'feature_file'); @@ -422,19 +415,16 @@ void main() { final repoDir = setupRepo(Directory(mergeRepoPath)); final conflictRepo = Repository.open(repoDir.path); - final conflictBranch = Branch.lookup( - repo: conflictRepo, - name: 'their-conflict', - ); - final commit = AnnotatedCommit.lookup( - repo: conflictRepo, - oid: conflictBranch.target, - ); - Checkout.reference(repo: conflictRepo, name: 'refs/heads/feature'); conflictRepo.setHead('refs/heads/feature'); - Merge.commit(repo: conflictRepo, commit: commit); + Merge.commit( + repo: conflictRepo, + commit: AnnotatedCommit.lookup( + repo: conflictRepo, + oid: Branch.lookup(repo: conflictRepo, name: 'their-conflict').target, + ), + ); final conflictedFile = conflictRepo.index.conflicts['feature_file']!; expect(conflictedFile.ancestor?.path, 'feature_file'); @@ -450,17 +440,18 @@ void main() { final repoDir = setupRepo(Directory(mergeRepoPath)); final conflictRepo = Repository.open(repoDir.path); - final conflictBranch = Branch.lookup( - repo: conflictRepo, - name: 'conflict-branch', - ); - final commit = AnnotatedCommit.lookup( - repo: conflictRepo, - oid: conflictBranch.target, - ); final index = conflictRepo.index; - Merge.commit(repo: conflictRepo, commit: commit); + Merge.commit( + repo: conflictRepo, + commit: AnnotatedCommit.lookup( + repo: conflictRepo, + oid: Branch.lookup( + repo: conflictRepo, + name: 'conflict-branch', + ).target, + ), + ); expect(index.hasConflicts, true); expect(index['.gitignore'].isConflict, false); @@ -490,17 +481,18 @@ void main() { final repoDir = setupRepo(Directory(mergeRepoPath)); final conflictRepo = Repository.open(repoDir.path); - final conflictBranch = Branch.lookup( - repo: conflictRepo, - name: 'conflict-branch', - ); - final commit = AnnotatedCommit.lookup( - repo: conflictRepo, - oid: conflictBranch.target, - ); final index = conflictRepo.index; - Merge.commit(repo: conflictRepo, commit: commit); + Merge.commit( + repo: conflictRepo, + commit: AnnotatedCommit.lookup( + repo: conflictRepo, + oid: Branch.lookup( + repo: conflictRepo, + name: 'conflict-branch', + ).target, + ), + ); expect(index.hasConflicts, true); expect(index.conflicts.length, 1); diff --git a/test/merge_test.dart b/test/merge_test.dart index db98711..8102d9d 100644 --- a/test/merge_test.dart +++ b/test/merge_test.dart @@ -26,11 +26,13 @@ void main() { group('Merge', () { group('analysis', () { test('is up to date when no reference is provided', () { - final result = Merge.analysis(repo: repo, theirHead: repo['c68ff54']); - expect(result, [ - {GitMergeAnalysis.upToDate}, - GitMergePreference.none, - ]); + expect( + Merge.analysis(repo: repo, theirHead: repo['c68ff54']), + [ + {GitMergeAnalysis.upToDate}, + GitMergePreference.none, + ], + ); expect(repo.status, isEmpty); }); @@ -45,11 +47,10 @@ void main() { }); test('is fast forward', () { - final ffCommit = Commit.lookup(repo: repo, oid: repo['f17d0d4']); final ffBranch = Branch.create( repo: repo, name: 'ff-branch', - target: ffCommit, + target: Commit.lookup(repo: repo, oid: repo['f17d0d4']), ); final result = Merge.analysis( @@ -73,10 +74,6 @@ void main() { test('writes conflicts to index', () { final conflictBranch = Branch.lookup(repo: repo, name: 'conflict-branch'); - final commit = AnnotatedCommit.lookup( - repo: repo, - oid: conflictBranch.target, - ); final index = repo.index; final result = Merge.analysis( @@ -85,7 +82,10 @@ void main() { ); expect(result[0], {GitMergeAnalysis.normal}); - Merge.commit(repo: repo, commit: commit); + Merge.commit( + repo: repo, + commit: AnnotatedCommit.lookup(repo: repo, oid: conflictBranch.target), + ); expect(index.hasConflicts, true); expect(index.conflicts.length, 1); expect(repo.state, GitRepositoryState.merge); @@ -122,19 +122,16 @@ master conflict edit conflict branch edit >>>>>>> conflict_file """; - final conflictBranch = Branch.lookup( - repo: repo, - name: 'conflict-branch', - ); - final commit = AnnotatedCommit.lookup( - repo: repo, - oid: conflictBranch.target, - ); - final index = repo.index; - Merge.commit(repo: repo, commit: commit); + Merge.commit( + repo: repo, + commit: AnnotatedCommit.lookup( + repo: repo, + oid: Branch.lookup(repo: repo, name: 'conflict-branch').target, + ), + ); - final conflictedFile = index.conflicts['conflict_file']!; + final conflictedFile = repo.index.conflicts['conflict_file']!; final diff = Merge.fileFromIndex( repo: repo, ancestor: null, @@ -153,21 +150,19 @@ Feature edit on feature branch Another feature edit >>>>>>> feature_file """; - final conflictBranch = Branch.lookup( - repo: repo, - name: 'ancestor-conflict', - ); - final commit = AnnotatedCommit.lookup( - repo: repo, - oid: conflictBranch.target, - ); + Checkout.reference(repo: repo, name: 'refs/heads/feature'); repo.setHead('refs/heads/feature'); - final index = repo.index; - Merge.commit(repo: repo, commit: commit); + Merge.commit( + repo: repo, + commit: AnnotatedCommit.lookup( + repo: repo, + oid: Branch.lookup(repo: repo, name: 'ancestor-conflict').target, + ), + ); - final conflictedFile = index.conflicts['feature_file']!; + final conflictedFile = repo.index.conflicts['feature_file']!; final diff = Merge.fileFromIndex( repo: repo, ancestor: conflictedFile.ancestor, @@ -186,24 +181,18 @@ master conflict edit conflict branch edit >>>>>>> conflict_file """; - final conflictBranch = Branch.lookup( - repo: repo, - name: 'conflict-branch', - ); - final commit = AnnotatedCommit.lookup( - repo: repo, - oid: conflictBranch.target, - ); - final index = repo.index; Merge.commit( repo: repo, - commit: commit, + commit: AnnotatedCommit.lookup( + repo: repo, + oid: Branch.lookup(repo: repo, name: 'conflict-branch').target, + ), mergeFlags: {GitMergeFlag.noRecursive}, fileFlags: {GitMergeFileFlag.ignoreWhitespaceEOL}, ); - final conflictedFile = index.conflicts['conflict_file']!; + final conflictedFile = repo.index.conflicts['conflict_file']!; final diff = Merge.fileFromIndex( repo: repo, ancestor: null, @@ -215,19 +204,16 @@ conflict branch edit }); test('merges with provided merge favor', () { - final conflictBranch = Branch.lookup( + Merge.commit( repo: repo, - name: 'conflict-branch', + commit: AnnotatedCommit.lookup( + repo: repo, + oid: Branch.lookup(repo: repo, name: 'conflict-branch').target, + ), + favor: GitMergeFileFavor.ours, ); - final commit = AnnotatedCommit.lookup( - repo: repo, - oid: conflictBranch.target, - ); - final index = repo.index; - Merge.commit(repo: repo, commit: commit, favor: GitMergeFileFavor.ours); - - expect(index.conflicts, isEmpty); + expect(repo.index.conflicts, isEmpty); expect( File(p.join(repo.workdir, 'conflict_file')).readAsStringSync(), 'master conflict edit\n', @@ -305,49 +291,40 @@ theirs content group('merge commits', () { test('merges with default values', () { final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']); - final theirCommitAnnotated = AnnotatedCommit.lookup( - repo: repo, - oid: theirCommit.oid, - ); - final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']); final mergeIndex = Merge.commits( repo: repo, - ourCommit: ourCommit, + ourCommit: Commit.lookup(repo: repo, oid: repo['1490545']), theirCommit: theirCommit, ); expect(mergeIndex.conflicts, isEmpty); final mergeCommitsTree = mergeIndex.writeTree(repo); - Merge.commit(repo: repo, commit: theirCommitAnnotated); - final index = repo.index; - expect(index.conflicts, isEmpty); - final mergeTree = index.writeTree(); + Merge.commit( + repo: repo, + commit: AnnotatedCommit.lookup(repo: repo, oid: theirCommit.oid), + ); + expect(repo.index.conflicts, isEmpty); + final mergeTree = repo.index.writeTree(); expect(mergeCommitsTree == mergeTree, true); }); test('merges with provided favor', () { - final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']); - final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']); - final mergeIndex = Merge.commits( repo: repo, - ourCommit: ourCommit, - theirCommit: theirCommit, + ourCommit: Commit.lookup(repo: repo, oid: repo['1490545']), + theirCommit: Commit.lookup(repo: repo, oid: repo['5aecfa0']), favor: GitMergeFileFavor.ours, ); expect(mergeIndex.conflicts, isEmpty); }); test('merges with provided merge and file flags', () { - final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']); - final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']); - final mergeIndex = Merge.commits( repo: repo, - ourCommit: ourCommit, - theirCommit: theirCommit, + ourCommit: Commit.lookup(repo: repo, oid: repo['1490545']), + theirCommit: Commit.lookup(repo: repo, oid: repo['5aecfa0']), mergeFlags: { GitMergeFlag.findRenames, GitMergeFlag.noRecursive, @@ -374,31 +351,33 @@ theirs content }); test('finds merge base for two commits', () { - var base = Merge.base( - repo: repo, - commits: [repo['1490545'], repo['5aecfa0']], + expect( + Merge.base(repo: repo, commits: [repo['1490545'], repo['5aecfa0']]).sha, + 'fc38877b2552ab554752d9a77e1f48f738cca79b', ); - expect(base.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b'); - base = Merge.base( - repo: repo, - commits: [repo['f17d0d4'], repo['5aecfa0']], + expect( + Merge.base(repo: repo, commits: [repo['f17d0d4'], repo['5aecfa0']]).sha, + 'f17d0d48eae3aa08cecf29128a35e310c97b3521', ); - expect(base.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521'); }); test('finds merge base for many commits', () { - var base = Merge.base( - repo: repo, - commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']], + expect( + Merge.base( + repo: repo, + commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']], + ).sha, + 'fc38877b2552ab554752d9a77e1f48f738cca79b', ); - expect(base.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b'); - base = Merge.base( - repo: repo, - commits: [repo['f17d0d4'], repo['5aecfa0'], repo['0e409d6']], + expect( + Merge.base( + repo: repo, + commits: [repo['f17d0d4'], repo['5aecfa0'], repo['0e409d6']], + ).sha, + 'f17d0d48eae3aa08cecf29128a35e310c97b3521', ); - expect(base.sha, 'f17d0d48eae3aa08cecf29128a35e310c97b3521'); }); test('throws when trying to find merge base for invalid oid', () { @@ -420,11 +399,13 @@ theirs content }); test('finds octopus merge base', () { - final base = Merge.octopusBase( - repo: repo, - commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']], + expect( + Merge.octopusBase( + repo: repo, + commits: [repo['1490545'], repo['0e409d6'], repo['5aecfa0']], + ).sha, + 'fc38877b2552ab554752d9a77e1f48f738cca79b', ); - expect(base.sha, 'fc38877b2552ab554752d9a77e1f48f738cca79b'); }); test('throws when trying to find octopus merge base for invalid oid', () { @@ -440,10 +421,6 @@ theirs content group('merge trees', () { test('merges with default values', () { final theirCommit = Commit.lookup(repo: repo, oid: repo['5aecfa0']); - final theirCommitAnnotated = AnnotatedCommit.lookup( - repo: repo, - oid: theirCommit.oid, - ); final ourCommit = Commit.lookup(repo: repo, oid: repo['1490545']); final baseCommit = Commit.lookup( repo: repo, @@ -463,11 +440,13 @@ theirs content final mergeTreesTree = mergeIndex.writeTree(repo); repo.setHead(ourCommit.oid); - Merge.commit(repo: repo, commit: theirCommitAnnotated); - final index = repo.index; - expect(index.conflicts, isEmpty); - final mergeTree = index.writeTree(); + Merge.commit( + repo: repo, + commit: AnnotatedCommit.lookup(repo: repo, oid: theirCommit.oid), + ); + expect(repo.index.conflicts, isEmpty); + final mergeTree = repo.index.writeTree(); expect(mergeTreesTree == mergeTree, true); }); @@ -506,19 +485,17 @@ theirs content }); test('cherry-picks commit', () { - final cherry = Commit.lookup(repo: repo, oid: repo['5aecfa0']); - Merge.cherryPick(repo: repo, commit: cherry); + Merge.cherryPick( + repo: repo, + commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']), + ); expect(repo.state, GitRepositoryState.cherrypick); expect(repo.message, 'add another feature file\n'); - final index = repo.index; - expect(index.conflicts, isEmpty); + expect(repo.index.conflicts, isEmpty); // pretend we've done commit repo.removeMessage(); - expect( - () => repo.message, - throwsA(isA()), - ); + expect(() => repo.message, throwsA(isA())); }); test('throws when error occurs', () { diff --git a/test/note_test.dart b/test/note_test.dart index ff749c1..6be3a08 100644 --- a/test/note_test.dart +++ b/test/note_test.dart @@ -73,10 +73,12 @@ void main() { note: 'New note for HEAD', force: true, ); - final noteBlob = Blob.lookup(repo: repo, oid: noteOid); expect(noteOid.sha, 'ffd6e2ceaf91c00ea6d29e2e897f906da720529f'); - expect(noteBlob.content, 'New note for HEAD'); + expect( + Blob.lookup(repo: repo, oid: noteOid).content, + 'New note for HEAD', + ); }); test('throws when trying to create note and error occurs', () { diff --git a/test/odb_test.dart b/test/odb_test.dart index ac0065d..6a722a9 100644 --- a/test/odb_test.dart +++ b/test/odb_test.dart @@ -45,10 +45,9 @@ void main() { }); test('reads object', () { - final oid = repo[blobSha]; - final object = repo.odb.read(oid); + final object = repo.odb.read(repo[blobSha]); - expect(object.oid, oid); + expect(object.oid, repo[blobSha]); expect(object.type, GitObject.blob); expect(object.data, blobContent); expect(object.size, 13); diff --git a/test/packbuilder_test.dart b/test/packbuilder_test.dart index 172b173..ff63c8a 100644 --- a/test/packbuilder_test.dart +++ b/test/packbuilder_test.dart @@ -73,9 +73,8 @@ void main() { test('adds commit', () { final packbuilder = PackBuilder(repo); - final oid = repo['f17d0d4']; - packbuilder.addCommit(oid); + packbuilder.addCommit(repo['f17d0d4']); expect(packbuilder.length, 3); }); @@ -90,9 +89,8 @@ void main() { test('adds tree', () { final packbuilder = PackBuilder(repo); - final oid = repo['df2b8fc']; - packbuilder.addTree(oid); + packbuilder.addTree(repo['df2b8fc']); expect(packbuilder.length, 2); }); @@ -106,11 +104,10 @@ void main() { }); test('adds objects with walker', () { - final oid = repo['f17d0d4']; final packbuilder = PackBuilder(repo); final walker = RevWalk(repo); walker.sorting({GitSort.none}); - walker.push(oid); + walker.push(repo['f17d0d4']); packbuilder.addWalk(walker); expect(packbuilder.length, 3); @@ -134,20 +131,16 @@ void main() { test('packs with default arguments', () { final objectsCount = repo.odb.objects.length; Directory(packDirPath).createSync(); - - final writtenCount = repo.pack(); - - expect(writtenCount, objectsCount); + expect(repo.pack(), objectsCount); }); test('packs into provided path with threads set', () { - final objectsCount = repo.odb.objects.length; final testPackPath = p.join(repo.workdir, 'test-pack'); Directory(testPackPath).createSync(); final writtenCount = repo.pack(path: testPackPath, threads: 1); - expect(writtenCount, objectsCount); + expect(writtenCount, repo.odb.objects.length); expect(Directory(testPackPath).listSync().isNotEmpty, true); }); @@ -167,8 +160,7 @@ void main() { } } - final writtenCount = repo.pack(packDelegate: packDelegate); - expect(writtenCount, 18); + expect(repo.pack(packDelegate: packDelegate), 18); }); test('throws when trying to write pack into invalid path', () { diff --git a/test/patch_test.dart b/test/patch_test.dart index 0c0959d..8ffd7df 100644 --- a/test/patch_test.dart +++ b/test/patch_test.dart @@ -90,11 +90,9 @@ index e69de29..0000000 }); test('creates from blobs', () { - final oldBlob = Blob.lookup(repo: repo, oid: oldBlobOid); - final newBlob = Blob.lookup(repo: repo, oid: newBlobOid); final patch = Patch.fromBlobs( - oldBlob: oldBlob, - newBlob: newBlob, + oldBlob: Blob.lookup(repo: repo, oid: oldBlobOid), + newBlob: Blob.lookup(repo: repo, oid: newBlobOid), oldBlobPath: path, newBlobPath: path, ); @@ -103,10 +101,9 @@ index e69de29..0000000 }); test('creates from one blob (add)', () { - final newBlob = Blob.lookup(repo: repo, oid: newBlobOid); final patch = Patch.fromBlobs( oldBlob: null, - newBlob: newBlob, + newBlob: Blob.lookup(repo: repo, oid: newBlobOid), oldBlobPath: path, newBlobPath: path, ); @@ -115,9 +112,8 @@ index e69de29..0000000 }); test('creates from one blob (delete)', () { - final oldBlob = Blob.lookup(repo: repo, oid: oldBlobOid); final patch = Patch.fromBlobs( - oldBlob: oldBlob, + oldBlob: Blob.lookup(repo: repo, oid: oldBlobOid), newBlob: null, oldBlobPath: path, newBlobPath: path, @@ -127,9 +123,8 @@ index e69de29..0000000 }); test('creates from blob and buffer', () { - final blob = Blob.lookup(repo: repo, oid: oldBlobOid); final patch = Patch.fromBlobAndBuffer( - blob: blob, + blob: Blob.lookup(repo: repo, oid: oldBlobOid), buffer: newBuffer, blobPath: path, bufferPath: path, diff --git a/test/rebase_test.dart b/test/rebase_test.dart index 0348277..353f5ef 100644 --- a/test/rebase_test.dart +++ b/test/rebase_test.dart @@ -33,15 +33,7 @@ void main() { time: 1234, ); final master = Reference.lookup(repo: repo, name: 'refs/heads/master'); - final branchHead = AnnotatedCommit.fromReference( - repo: repo, - reference: master, - ); final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature'); - final ontoHead = AnnotatedCommit.fromReference( - repo: repo, - reference: feature, - ); Checkout.reference(repo: repo, name: feature.name); repo.setHead(feature.name); @@ -49,8 +41,8 @@ void main() { final rebase = Rebase.init( repo: repo, - branch: branchHead, - onto: ontoHead, + branch: AnnotatedCommit.fromReference(repo: repo, reference: master), + onto: AnnotatedCommit.fromReference(repo: repo, reference: feature), ); expect(rebase.origHeadOid, master.target); @@ -85,11 +77,10 @@ void main() { time: 1234, ); final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature'); - final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: feature.target); final rebase = Rebase.init( repo: repo, - onto: ontoHead, + onto: AnnotatedCommit.lookup(repo: repo, oid: feature.target), ); expect( @@ -126,9 +117,7 @@ void main() { time: 1234, ); final master = Reference.lookup(repo: repo, name: 'refs/heads/master'); - final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target); final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature'); - final upstream = AnnotatedCommit.lookup(repo: repo, oid: repo[shas[1]]); Checkout.reference(repo: repo, name: feature.name); repo.setHead(feature.name); @@ -136,8 +125,8 @@ void main() { final rebase = Rebase.init( repo: repo, - branch: branchHead, - upstream: upstream, + branch: AnnotatedCommit.lookup(repo: repo, oid: master.target), + upstream: AnnotatedCommit.lookup(repo: repo, oid: repo[shas[1]]), ); expect(rebase.origHeadOid, master.target); @@ -172,21 +161,21 @@ void main() { email: 'author@email.com', time: 1234, ); - final master = Reference.lookup(repo: repo, name: 'refs/heads/master'); - final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target); final conflict = Reference.lookup( repo: repo, name: 'refs/heads/conflict-branch', ); - final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target); Checkout.reference(repo: repo, name: conflict.name); repo.setHead(conflict.name); final rebase = Rebase.init( repo: repo, - branch: branchHead, - onto: ontoHead, + branch: AnnotatedCommit.lookup( + repo: repo, + oid: Reference.lookup(repo: repo, name: 'refs/heads/master').target, + ), + onto: AnnotatedCommit.lookup(repo: repo, oid: conflict.target), ); expect(rebase.operations.length, 1); @@ -201,21 +190,21 @@ void main() { test('throws when trying to perfrom next rebase operation and error occurs', () { - final master = Reference.lookup(repo: repo, name: 'refs/heads/master'); - final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target); final conflict = Reference.lookup( repo: repo, name: 'refs/heads/conflict-branch', ); - final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target); Checkout.reference(repo: repo, name: conflict.name); repo.setHead(conflict.name); final rebase = Rebase.init( repo: repo, - branch: branchHead, - onto: ontoHead, + branch: AnnotatedCommit.lookup( + repo: repo, + oid: Reference.lookup(repo: repo, name: 'refs/heads/master').target, + ), + onto: AnnotatedCommit.lookup(repo: repo, oid: conflict.target), ); expect(rebase.operations.length, 1); @@ -224,21 +213,21 @@ void main() { }); test('aborts rebase in progress', () { - final master = Reference.lookup(repo: repo, name: 'refs/heads/master'); - final branchHead = AnnotatedCommit.lookup(repo: repo, oid: master.target); final conflict = Reference.lookup( repo: repo, name: 'refs/heads/conflict-branch', ); - final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: conflict.target); Checkout.reference(repo: repo, name: conflict.name); repo.setHead(conflict.name); final rebase = Rebase.init( repo: repo, - branch: branchHead, - onto: ontoHead, + branch: AnnotatedCommit.lookup( + repo: repo, + oid: Reference.lookup(repo: repo, name: 'refs/heads/master').target, + ), + onto: AnnotatedCommit.lookup(repo: repo, oid: conflict.target), ); expect(rebase.operations.length, 1); @@ -252,12 +241,12 @@ void main() { }); test('opens an existing rebase', () { - final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature'); - final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: feature.target); - final rebase = Rebase.init( repo: repo, - onto: ontoHead, + onto: AnnotatedCommit.lookup( + repo: repo, + oid: Reference.lookup(repo: repo, name: 'refs/heads/feature').target, + ), ); expect(rebase.operations.length, 3); @@ -270,11 +259,12 @@ void main() { }); test('manually releases allocated memory', () { - final feature = Reference.lookup(repo: repo, name: 'refs/heads/feature'); - final ontoHead = AnnotatedCommit.lookup(repo: repo, oid: feature.target); final rebase = Rebase.init( repo: repo, - onto: ontoHead, + onto: AnnotatedCommit.lookup( + repo: repo, + oid: Reference.lookup(repo: repo, name: 'refs/heads/feature').target, + ), ); expect(() => rebase.free(), returnsNormally); diff --git a/test/reference_test.dart b/test/reference_test.dart index 6f06585..4345317 100644 --- a/test/reference_test.dart +++ b/test/reference_test.dart @@ -47,9 +47,10 @@ void main() { test('returns correct type of reference', () { expect(repo.head.type, ReferenceType.direct); - - final ref = Reference.lookup(repo: repo, name: 'HEAD'); - expect(ref.type, ReferenceType.symbolic); + expect( + Reference.lookup(repo: repo, name: 'HEAD').type, + ReferenceType.symbolic, + ); }); test('returns SHA hex of direct reference', () { @@ -57,8 +58,10 @@ void main() { }); test('returns SHA hex of symbolic reference', () { - final ref = Reference.lookup(repo: repo, name: 'HEAD'); - expect(ref.target.sha, lastCommit); + expect( + Reference.lookup(repo: repo, name: 'HEAD').target.sha, + lastCommit, + ); }); test('throws when trying to resolve invalid reference', () { @@ -84,13 +87,17 @@ void main() { }); test('checks if reference is a local branch', () { - final ref = Reference.lookup(repo: repo, name: 'refs/heads/feature'); - expect(ref.isBranch, true); + expect( + Reference.lookup(repo: repo, name: 'refs/heads/feature').isBranch, + true, + ); }); test('checks if reference is a note', () { - final ref = Reference.lookup(repo: repo, name: 'refs/heads/master'); - expect(ref.isNote, false); + expect( + Reference.lookup(repo: repo, name: 'refs/heads/master').isNote, + false, + ); }); test('checks if reference is a remote branch', () { @@ -102,16 +109,22 @@ void main() { }); test('checks if reference is a tag', () { - final ref = Reference.lookup(repo: repo, name: 'refs/tags/v0.1'); - expect(ref.isTag, true); + expect( + Reference.lookup(repo: repo, name: 'refs/tags/v0.1').isTag, + true, + ); }); test('checks if reflog exists for the reference', () { - var ref = Reference.lookup(repo: repo, name: 'refs/heads/master'); - expect(ref.hasLog, true); + expect( + Reference.lookup(repo: repo, name: 'refs/heads/master').hasLog, + true, + ); - ref = Reference.lookup(repo: repo, name: 'refs/tags/v0.1'); - expect(ref.hasLog, false); + expect( + Reference.lookup(repo: repo, name: 'refs/tags/v0.1').hasLog, + false, + ); }); test('ensures updates to the reference will append to its log', () { @@ -148,12 +161,10 @@ void main() { group('create direct', () { test('creates with oid as target', () { - final ref = Reference.lookup(repo: repo, name: 'refs/heads/master'); - Reference.create( repo: repo, name: 'refs/tags/from.oid', - target: ref.target, + target: repo.head.target, ); expect(repo.references, contains('refs/tags/from.oid')); @@ -319,7 +330,6 @@ void main() { test('deletes reference', () { expect(repo.references, contains('refs/tags/v0.1')); - Reference.delete(repo: repo, name: 'refs/tags/v0.1'); expect(repo.references, isNot(contains('refs/tags/v0.1'))); }); @@ -470,15 +480,13 @@ void main() { test('peels to object of provided type', () { final ref = Reference.lookup(repo: repo, name: 'refs/heads/master'); - final blob = Blob.lookup(repo: repo, oid: repo['9c78c21']); final blobRef = Reference.create( repo: repo, name: 'refs/tags/blob', - target: blob.oid, + target: Blob.lookup(repo: repo, oid: repo['9c78c21']).oid, ); final tagRef = Reference.lookup(repo: repo, name: 'refs/tags/v0.2'); final commit = Commit.lookup(repo: repo, oid: ref.target); - final tree = commit.tree; final peeledCommit = ref.peel(GitObject.commit) as Commit; final peeledTree = ref.peel(GitObject.tree) as Tree; @@ -486,7 +494,7 @@ void main() { final peeledTag = tagRef.peel(GitObject.tag) as Tag; expect(peeledCommit.oid, commit.oid); - expect(peeledTree.oid, tree.oid); + expect(peeledTree.oid, commit.tree.oid); expect(peeledBlob.content, 'Feature edit\n'); expect(peeledTag.name, 'v0.2'); }); diff --git a/test/remote_prune_test.dart b/test/remote_prune_test.dart index d91da24..9ac3ee7 100644 --- a/test/remote_prune_test.dart +++ b/test/remote_prune_test.dart @@ -40,7 +40,6 @@ void main() { group('Remote', () { test('fetch() does not prune branch by default', () { remote.fetch(); - expect( clonedRepo.branches.any((branch) => branch.name == 'origin/feature'), true, @@ -49,7 +48,6 @@ void main() { test('fetch() prunes branch with provided flag', () { remote.fetch(prune: GitFetchPrune.prune); - expect( clonedRepo.branches.any((branch) => branch.name == 'origin/feature'), false, @@ -58,7 +56,6 @@ void main() { test('fetch() does not prune branch with provided flag', () { remote.fetch(prune: GitFetchPrune.noPrune); - expect( clonedRepo.branches.any((branch) => branch.name == 'origin/feature'), true, diff --git a/test/remote_test.dart b/test/remote_test.dart index d82e793..90d8956 100644 --- a/test/remote_test.dart +++ b/test/remote_test.dart @@ -75,12 +75,7 @@ void main() { 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()), ); }); @@ -110,13 +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'); + final renamedRemote = Remote.lookup(repo: repo, name: 'renamed'); + expect(renamedRemote.name, 'renamed'); }); test('returns list of non-default refspecs that cannot be renamed', () { @@ -141,14 +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); + expect(Remote.lookup(repo: repo, name: remoteName).url, newUrl); }); test('throws when trying to set invalid url name', () { @@ -162,8 +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); + expect(Remote.lookup(repo: repo, name: remoteName).pushUrl, newUrl); }); test('throws when trying to set invalid push url name', () { @@ -201,8 +193,7 @@ void main() { 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'), @@ -404,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); @@ -435,13 +425,9 @@ 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); }, tags: 'remote_fetch', @@ -483,9 +469,7 @@ 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); }, tags: 'remote_fetch', @@ -513,9 +497,10 @@ 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', diff --git a/test/repository_test.dart b/test/repository_test.dart index 8a79323..0d7320c 100644 --- a/test/repository_test.dart +++ b/test/repository_test.dart @@ -171,8 +171,10 @@ void main() { test('cleans up state', () { expect(repo.state, GitRepositoryState.none); - final commit = Commit.lookup(repo: repo, oid: repo['5aecfa0']); - Merge.cherryPick(repo: repo, commit: commit); + Merge.cherryPick( + repo: repo, + commit: Commit.lookup(repo: repo, oid: repo['5aecfa0']), + ); expect(repo.state, GitRepositoryState.cherrypick); repo.stateCleanup(); diff --git a/test/reset_test.dart b/test/reset_test.dart index 2bd907b..54e3725 100644 --- a/test/reset_test.dart +++ b/test/reset_test.dart @@ -25,33 +25,27 @@ void main() { group('Reset', () { test('resets with hard', () { - var contents = file.readAsStringSync(); - expect(contents, 'Feature edit\n'); + expect(file.readAsStringSync(), 'Feature edit\n'); repo.reset(oid: repo[sha], resetType: GitReset.hard); - contents = file.readAsStringSync(); - expect(contents, isEmpty); + expect(file.readAsStringSync(), isEmpty); }); test('resets with soft', () { - var contents = file.readAsStringSync(); - expect(contents, 'Feature edit\n'); + expect(file.readAsStringSync(), 'Feature edit\n'); repo.reset(oid: repo[sha], resetType: GitReset.soft); - contents = file.readAsStringSync(); - expect(contents, 'Feature edit\n'); + expect(file.readAsStringSync(), 'Feature edit\n'); final diff = Diff.indexToWorkdir(repo: repo, index: repo.index); expect(diff.deltas, isEmpty); }); test('resets with mixed', () { - var contents = file.readAsStringSync(); - expect(contents, 'Feature edit\n'); + expect(file.readAsStringSync(), 'Feature edit\n'); repo.reset(oid: repo[sha], resetType: GitReset.mixed); - contents = file.readAsStringSync(); - expect(contents, 'Feature edit\n'); + expect(file.readAsStringSync(), 'Feature edit\n'); final diff = Diff.indexToWorkdir(repo: repo, index: repo.index); expect(diff.deltas.length, 1); diff --git a/test/revwalk_test.dart b/test/revwalk_test.dart index 53f5a1a..a960f71 100644 --- a/test/revwalk_test.dart +++ b/test/revwalk_test.dart @@ -42,9 +42,8 @@ void main() { test('returns list of commits with default sorting', () { final walker = RevWalk(repo); - final start = Oid.fromSHA(repo: repo, sha: log.first); - walker.push(start); + walker.push(repo[log.first]); final commits = walker.walk(); for (var i = 0; i < commits.length; i++) { @@ -54,9 +53,8 @@ void main() { test('returns list of commits with reverse sorting', () { final walker = RevWalk(repo); - final start = Oid.fromSHA(repo: repo, sha: log.first); - walker.push(start); + walker.push(repo[log.first]); walker.sorting({GitSort.reverse}); final commits = walker.walk(); @@ -67,9 +65,8 @@ void main() { test('changes sorting', () { final walker = RevWalk(repo); - final start = Oid.fromSHA(repo: repo, sha: log.first); - walker.push(start); + walker.push(repo[log.first]); final timeSortedCommits = walker.walk(); for (var i = 0; i < timeSortedCommits.length; i++) { @@ -161,28 +158,26 @@ void main() { }); test('hides head', () { - final head = repo.head; final walker = RevWalk(repo); - walker.push(head.target); + walker.push(repo.head.target); final commits = walker.walk(); expect(commits.length, 6); - walker.push(head.target); + walker.push(repo.head.target); walker.hideHead(); final hiddenCommits = walker.walk(); expect(hiddenCommits.length, 0); }); test('hides oids of reference with provided name', () { - final head = repo.head; final walker = RevWalk(repo); - walker.push(head.target); + walker.push(repo.head.target); final commits = walker.walk(); expect(commits.length, 6); - walker.push(head.target); + walker.push(repo.head.target); walker.hideReference('refs/heads/master'); final hiddenCommits = walker.walk(); expect(hiddenCommits.length, 0); @@ -197,9 +192,8 @@ void main() { test('resets walker', () { final walker = RevWalk(repo); - final start = Oid.fromSHA(repo: repo, sha: log.first); - walker.push(start); + walker.push(repo[log.first]); walker.reset(); final commits = walker.walk(); @@ -209,15 +203,12 @@ void main() { test('simplifies walker by enqueuing only first parent for each commit', () { final walker = RevWalk(repo); - final start = Oid.fromSHA(repo: repo, sha: log.first); - walker.push(start); + walker.push(repo[log.first]); walker.simplifyFirstParent(); final commits = walker.walk(); - for (var i = 0; i < commits.length; i++) { - expect(commits.length, 3); - } + expect(commits.length, 3); }); test('throws when trying to add new root for traversal and error occurs', diff --git a/test/submodule_test.dart b/test/submodule_test.dart index 20e03b4..3438b5d 100644 --- a/test/submodule_test.dart +++ b/test/submodule_test.dart @@ -68,8 +68,11 @@ void main() { }); test('updates with provided init flag', () { - final submoduleFilePath = - p.join(repo.workdir, testSubmodule, 'master.txt'); + final submoduleFilePath = p.join( + repo.workdir, + testSubmodule, + 'master.txt', + ); expect(File(submoduleFilePath).existsSync(), false); Submodule.update(repo: repo, name: testSubmodule, init: true); diff --git a/test/tag_test.dart b/test/tag_test.dart index 6234b4a..49b3cf0 100644 --- a/test/tag_test.dart +++ b/test/tag_test.dart @@ -49,14 +49,13 @@ void main() { offset: 180, ); final target = tag.target as Commit; - final tagger = tag.tagger; expect(tag.oid, tagOid); expect(tag.name, 'v0.2'); expect(tag.message, 'annotated tag\n'); expect(tag.targetType, GitObject.commit); expect(target.message, 'add subdirectory file\n'); - expect(tagger, signature); + expect(tag.tagger, signature); expect(tag.toString(), contains('Tag{')); }); @@ -81,14 +80,13 @@ void main() { ); final newTag = Tag.lookup(repo: repo, oid: oid); - final tagger = newTag.tagger; final newTagTarget = newTag.target as Commit; expect(newTag.oid, oid); expect(newTag.name, tagName); expect(newTag.message, message); expect(newTag.targetOid.sha, targetSHA); - expect(tagger, signature); + expect(newTag.tagger, signature); expect(newTagTarget.oid, target); }); @@ -129,13 +127,12 @@ void main() { ); final newTag = Tag.lookup(repo: repo, oid: oid); - final tagger = newTag.tagger; final newTagTarget = newTag.target as Tree; expect(newTag.oid, oid); expect(newTag.name, tagName); expect(newTag.message, message); - expect(tagger, signature); + expect(newTag.tagger, signature); expect(newTagTarget.oid, target); }); @@ -176,13 +173,12 @@ void main() { ); final newTag = Tag.lookup(repo: repo, oid: oid); - final tagger = newTag.tagger; final newTagTarget = newTag.target as Blob; expect(newTag.oid, oid); expect(newTag.name, tagName); expect(newTag.message, message); - expect(tagger, signature); + expect(newTag.tagger, signature); expect(newTagTarget.oid, target); }); @@ -222,13 +218,12 @@ void main() { ); final newTag = Tag.lookup(repo: repo, oid: oid); - final tagger = newTag.tagger; final newTagTarget = newTag.target as Tag; expect(newTag.oid, oid); expect(newTag.name, tagName); expect(newTag.message, message); - expect(tagger, signature); + expect(newTag.tagger, signature); expect(newTagTarget.oid, tag.oid); }); @@ -275,14 +270,13 @@ void main() { ); final newTag = Tag.lookup(repo: repo, oid: oid); - final tagger = newTag.tagger; final newTagTarget = newTag.target as Commit; expect(newTag.oid, oid); expect(newTag.name, tagName); expect(newTag.message, message); expect(newTag.targetOid.sha, targetSHA); - expect(tagger, signature); + expect(newTag.tagger, signature); expect(newTagTarget.oid, target); expect(repo.tags.length, equals(2)); }); diff --git a/test/treebuilder_test.dart b/test/treebuilder_test.dart index 9cd2c46..e83ac15 100644 --- a/test/treebuilder_test.dart +++ b/test/treebuilder_test.dart @@ -32,11 +32,10 @@ void main() { test('initializes tree builder with provided tree', () { final builder = TreeBuilder(repo: repo, tree: tree); - final oid = builder.write(); expect(builder, isA()); expect(builder.length, tree.length); - expect(oid, tree.oid); + expect(builder.write(), tree.oid); }); test('throws when trying to initialize and error occurs', () { diff --git a/test/worktree_test.dart b/test/worktree_test.dart index 4da3b99..9dad2a1 100644 --- a/test/worktree_test.dart +++ b/test/worktree_test.dart @@ -49,11 +49,10 @@ void main() { }); 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, []);