feat(reference): add ability to peel reference until object of specified type is found

This commit is contained in:
Aleksey Kulikov 2021-09-04 14:50:34 +03:00
parent 56713da648
commit f63808b4f8
4 changed files with 91 additions and 0 deletions

View file

@ -1,5 +1,6 @@
import 'dart:io';
import 'package:libgit2dart/src/git_types.dart';
import 'package:test/test.dart';
import 'package:libgit2dart/libgit2dart.dart';
import 'helpers/util.dart';
@ -485,5 +486,33 @@ void main() {
ref2.free();
ref3.free();
});
test('successfully peels to non-tag object when no type is provided', () {
final ref = repo.references['refs/heads/master'];
final commit = repo[ref.target.sha] as Commit;
final peeled = ref.peel() as Commit;
expect(peeled.id, commit.id);
peeled.free();
commit.free();
ref.free();
});
test('successfully peels to object of provided type', () {
final ref = repo.references['refs/heads/master'];
final commit = repo[ref.target.sha] as Commit;
final tree = repo[commit.tree.sha] as Tree;
final peeledCommit = ref.peel(GitObject.commit) as Commit;
final peeledTree = ref.peel(GitObject.tree) as Tree;
expect(peeledCommit.id, commit.id);
expect(peeledTree.id, tree.id);
peeledCommit.free();
commit.free();
tree.free();
ref.free();
});
});
}