feat(repository)!: add more aliases for api methods

BREAKING CHANGE: Make repository entry point for most operations
This commit is contained in:
Aleksey Kulikov 2021-10-11 20:06:36 +03:00
parent 9205a3ad82
commit 3a0fa75929
51 changed files with 1380 additions and 1062 deletions

View file

@ -6,15 +6,14 @@ import 'helpers/util.dart';
void main() {
late Repository repo;
late Directory tmpDir;
const mergeCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
const message = "Commit message.\n\nSome description.\n";
const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628';
late Signature author;
late Signature commiter;
late Tree tree;
late Oid mergeCommit;
const message = "Commit message.\n\nSome description.\n";
setUp(() async {
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
setUp(() {
tmpDir = setupRepo(Directory('test/assets/testrepo/'));
repo = Repository.open(tmpDir.path);
author = Signature.create(
name: 'Author Name',
@ -26,31 +25,35 @@ void main() {
email: 'commiter@email.com',
time: 124,
);
mergeCommit = repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8'];
tree = Tree.lookup(
repo: repo,
id: repo['7796359a96eb722939c24bafdb1afe9f07f2f628'],
);
});
tearDown(() async {
tearDown(() {
author.free();
commiter.free();
tree.free();
repo.free();
await tmpDir.delete(recursive: true);
tmpDir.deleteSync(recursive: true);
});
group('Commit', () {
test('successfully returns when 40 char sha hex is provided', () {
final commit = repo[mergeCommit] as Commit;
expect(commit, isA<Commit>());
commit.free();
});
test('successfully returns when sha hex is short', () {
final commit = repo[mergeCommit.substring(0, 5)] as Commit;
final commit = repo.lookupCommit(mergeCommit);
expect(commit, isA<Commit>());
commit.free();
});
test('successfully reverts commit', () {
final to = repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8'] as Commit;
final from = repo['821ed6e80627b8769d170a293862f9fc60825226'] as Commit;
final to = repo.lookupCommit(
repo['78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8'],
);
final from = repo.lookupCommit(
repo['821ed6e80627b8769d170a293862f9fc60825226'],
);
final index = repo.index;
expect(index.find('dir/dir_file.txt'), true);
@ -64,16 +67,16 @@ void main() {
});
test('successfully creates commit', () {
final oid = Commit.create(
repo: repo,
final parent = repo.lookupCommit(mergeCommit);
final oid = repo.createCommit(
message: message,
author: author,
commiter: commiter,
treeSHA: tree,
parents: [mergeCommit],
tree: tree,
parents: [parent],
);
final commit = repo[oid.sha] as Commit;
final commit = repo.lookupCommit(oid);
expect(commit.id.sha, oid.sha);
expect(commit.message, message);
@ -81,11 +84,12 @@ void main() {
expect(commit.author, author);
expect(commit.committer, commiter);
expect(commit.time, 124);
expect(commit.tree.id.sha, tree);
expect(commit.tree.id, tree.id);
expect(commit.parents.length, 1);
expect(commit.parents[0].sha, mergeCommit);
expect(commit.parents[0], mergeCommit);
commit.free();
parent.free();
});
test('successfully creates commit without parents', () {
@ -93,11 +97,11 @@ void main() {
message: message,
author: author,
commiter: commiter,
treeSHA: tree,
tree: tree,
parents: [],
);
final commit = repo[oid.sha] as Commit;
final commit = repo.lookupCommit(oid);
expect(commit.id.sha, oid.sha);
expect(commit.message, message);
@ -105,23 +109,28 @@ void main() {
expect(commit.author, author);
expect(commit.committer, commiter);
expect(commit.time, 124);
expect(commit.tree.id.sha, tree);
expect(commit.tree.id, tree.id);
expect(commit.parents.length, 0);
commit.free();
});
test('successfully creates commit with 2 parents', () {
final parent1 = repo.lookupCommit(mergeCommit);
final parent2 = repo.lookupCommit(
repo['fc38877b2552ab554752d9a77e1f48f738cca79b'],
);
final oid = Commit.create(
repo: repo,
message: message,
author: author,
commiter: commiter,
treeSHA: tree,
parents: [mergeCommit, 'fc38877b2552ab554752d9a77e1f48f738cca79b'],
tree: tree,
parents: [parent1, parent2],
);
final commit = repo[oid.sha] as Commit;
final commit = repo.lookupCommit(oid);
expect(commit.id.sha, oid.sha);
expect(commit.message, message);
@ -129,36 +138,13 @@ void main() {
expect(commit.author, author);
expect(commit.committer, commiter);
expect(commit.time, 124);
expect(commit.tree.id.sha, tree);
expect(commit.tree.id, tree.id);
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] as Commit;
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.id.sha, tree);
expect(commit.parents.length, 1);
expect(commit.parents[0].sha, mergeCommit);
expect(commit.parents[0], mergeCommit);
expect(commit.parents[1], parent2.id);
parent1.free();
parent2.free();
commit.free();
});
});