feat(blob): add more bindings and API methods (#21)

This commit is contained in:
Aleksey Kulikov 2021-12-20 18:02:53 +03:00 committed by GitHub
parent 39a71811cb
commit e6bfdc5a85
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
423 changed files with 1076 additions and 39 deletions

View file

@ -14,7 +14,7 @@ void main() {
const newBlobContent = 'New blob\n';
setUp(() {
tmpDir = setupRepo(Directory('test/assets/testrepo/'));
tmpDir = setupRepo(Directory('test/assets/attributes_repo/'));
repo = Repository.open(tmpDir.path);
});
@ -107,6 +107,55 @@ void main() {
);
});
test('duplicates blob', () {
final blob = repo.lookupBlob(repo[blobSHA]);
final dupBlob = blob.duplicate();
expect(blob.oid.sha, dupBlob.oid.sha);
dupBlob.free();
blob.free();
});
test('filters content of a blob', () {
final blobOid = repo.createBlob('clrf\nclrf\n');
final blob = repo.lookupBlob(blobOid);
expect(blob.filterContent(asPath: 'file.crlf'), 'clrf\r\nclrf\r\n');
blob.free();
});
test('filters content of a blob with provided commit for attributes', () {
repo.checkout(refName: 'refs/tags/v0.2');
final blobOid = repo.createBlob('clrf\nclrf\n');
final blob = repo.lookupBlob(blobOid);
final commit = repo.lookupCommit(
repo['d2f3abc9324a22a9f80fec2c131ec43c93430618'],
);
expect(
blob.filterContent(
asPath: 'file.crlf',
flags: {GitBlobFilter.attributesFromCommit},
attributesCommit: commit,
),
'clrf\r\nclrf\r\n',
);
commit.free();
blob.free();
});
test('throws when trying to filter content of a blob and error occurs', () {
expect(
() => Blob(nullptr).filterContent(asPath: ''),
throwsA(isA<LibGit2Error>()),
);
});
group('diff', () {
const path = 'feature_file';
const blobPatch = """