mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(blob): add bindings and api
This commit is contained in:
parent
88d064bda2
commit
f0803298c8
14 changed files with 455 additions and 143 deletions
100
test/blob_test.dart
Normal file
100
test/blob_test.dart
Normal file
|
@ -0,0 +1,100 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'helpers/util.dart';
|
||||
|
||||
void main() {
|
||||
late Repository repo;
|
||||
late Blob blob;
|
||||
final tmpDir = '${Directory.systemTemp.path}/blob_testrepo/';
|
||||
const blobSHA = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc';
|
||||
const blobContent = 'Feature edit\n';
|
||||
const newBlobContent = 'New blob\n';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
blob = Blob.lookup(repo, Oid.fromSHA(repo, blobSHA));
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
blob.free();
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
|
||||
group('Blob', () {
|
||||
test('successfully initializes blob from provided Oid', () {
|
||||
expect(blob, isA<Blob>());
|
||||
});
|
||||
|
||||
test('returns correct values', () {
|
||||
expect(blob.id.sha, blobSHA);
|
||||
expect(blob.isBinary, false);
|
||||
expect(blob.size, 13);
|
||||
expect(blob.content, blobContent);
|
||||
});
|
||||
|
||||
test('successfully creates new blob', () {
|
||||
final oid = Blob.create(repo, newBlobContent);
|
||||
final newBlob = Blob.lookup(repo, oid);
|
||||
|
||||
expect(newBlob.id.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6');
|
||||
expect(newBlob.isBinary, false);
|
||||
expect(newBlob.size, 9);
|
||||
expect(newBlob.content, newBlobContent);
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('successfully creates new blob from file at provided relative path',
|
||||
() {
|
||||
final oid = Blob.createFromWorkdir(repo, 'feature_file');
|
||||
final newBlob = Blob.lookup(repo, oid);
|
||||
|
||||
expect(newBlob.id.sha, blobSHA);
|
||||
expect(newBlob.isBinary, false);
|
||||
expect(newBlob.size, 13);
|
||||
expect(newBlob.content, blobContent);
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('throws when creating new blob from invalid path', () {
|
||||
expect(
|
||||
() => Blob.createFromWorkdir(repo, 'invalid/path.txt'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when creating new blob from path that is outside of working directory',
|
||||
() {
|
||||
final outsideFile =
|
||||
File('${Directory.current.absolute.path}/test/blob_test.dart');
|
||||
expect(
|
||||
() => Blob.createFromWorkdir(repo, outsideFile.path),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('successfully creates new blob from file at provided path', () {
|
||||
final outsideFile =
|
||||
File('${Directory.current.absolute.path}/test/blob_test.dart');
|
||||
final oid = Blob.createFromDisk(repo, outsideFile.path);
|
||||
final newBlob = Blob.lookup(repo, oid);
|
||||
|
||||
expect(newBlob, isA<Blob>());
|
||||
expect(newBlob.isBinary, false);
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
});
|
||||
}
|
|
@ -7,43 +7,43 @@ import 'helpers/util.dart';
|
|||
void main() {
|
||||
const mergeCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||
|
||||
group('Commit', () {
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/commit_testrepo/';
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/commit_testrepo/';
|
||||
|
||||
const message = "Commit message.\n\nSome description.\n";
|
||||
const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628';
|
||||
late Signature author;
|
||||
late Signature commiter;
|
||||
const message = "Commit message.\n\nSome description.\n";
|
||||
const tree = '7796359a96eb722939c24bafdb1afe9f07f2f628';
|
||||
late Signature author;
|
||||
late Signature commiter;
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
author = Signature.create(
|
||||
name: 'Author Name',
|
||||
email: 'author@email.com',
|
||||
time: 123,
|
||||
);
|
||||
commiter = Signature.create(
|
||||
name: 'Commiter',
|
||||
email: 'commiter@email.com',
|
||||
time: 124,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
author.free();
|
||||
commiter.free();
|
||||
repo.free();
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
author = Signature.create(
|
||||
name: 'Author Name',
|
||||
email: 'author@email.com',
|
||||
time: 123,
|
||||
);
|
||||
commiter = Signature.create(
|
||||
name: 'Commiter',
|
||||
email: 'commiter@email.com',
|
||||
time: 124,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
author.free();
|
||||
commiter.free();
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
|
||||
group('Commit', () {
|
||||
test('successfully returns when 40 char sha hex is provided', () {
|
||||
final commit = repo[mergeCommit];
|
||||
expect(commit, isA<Commit>());
|
||||
|
|
|
@ -18,17 +18,17 @@ void main() {
|
|||
|
||||
late Config config;
|
||||
|
||||
setUp(() {
|
||||
File('$tmpDir/$configFileName').writeAsStringSync(contents);
|
||||
config = Config.open('$tmpDir/$configFileName');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
config.free();
|
||||
File('$tmpDir/$configFileName').deleteSync();
|
||||
});
|
||||
|
||||
group('Config', () {
|
||||
setUp(() {
|
||||
File('$tmpDir/$configFileName').writeAsStringSync(contents);
|
||||
config = Config.open('$tmpDir/$configFileName');
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
config.free();
|
||||
File('$tmpDir/$configFileName').deleteSync();
|
||||
});
|
||||
|
||||
test('opens file successfully with provided path', () {
|
||||
expect(config, isA<Config>());
|
||||
});
|
||||
|
|
|
@ -6,27 +6,25 @@ import 'helpers/util.dart';
|
|||
|
||||
void main() {
|
||||
const lastCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/odb_testrepo/';
|
||||
|
||||
group('Odb', () {
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/odb_testrepo/';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.free();
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
group('Odb', () {
|
||||
test('successfully initializes', () {
|
||||
expect(repo.odb, isA<Odb>());
|
||||
repo.odb.free();
|
||||
|
|
|
@ -8,26 +8,26 @@ void main() {
|
|||
const sha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||
const biggerSha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e9';
|
||||
const lesserSha = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e7';
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/oid_testrepo/';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
|
||||
group('Oid', () {
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/oid_testrepo/';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
group('fromSHA()', () {
|
||||
test('initializes successfully', () {
|
||||
final oid = Oid.fromSHA(repo, sha);
|
||||
|
|
|
@ -7,27 +7,26 @@ import 'helpers/util.dart';
|
|||
void main() {
|
||||
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||
const newCommit = 'c68ff54aabf660fcdd9a2838d401583fe31249e3';
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/ref_testrepo/';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
|
||||
group('Reference', () {
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/ref_testrepo/';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
|
||||
test('returns a list', () {
|
||||
expect(
|
||||
repo.references.list(),
|
||||
|
|
|
@ -5,30 +5,29 @@ import 'package:libgit2dart/libgit2dart.dart';
|
|||
import 'helpers/util.dart';
|
||||
|
||||
void main() {
|
||||
group('RefLog', () {
|
||||
late Repository repo;
|
||||
late RefLog reflog;
|
||||
final tmpDir = '${Directory.systemTemp.path}/reflog_testrepo/';
|
||||
late Repository repo;
|
||||
late RefLog reflog;
|
||||
final tmpDir = '${Directory.systemTemp.path}/reflog_testrepo/';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
reflog = RefLog(repo.head);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.head.free();
|
||||
reflog.free();
|
||||
repo.free();
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
}
|
||||
await copyRepo(
|
||||
from: Directory('test/assets/testrepo/'),
|
||||
to: await Directory(tmpDir).create(),
|
||||
);
|
||||
repo = Repository.open(tmpDir);
|
||||
reflog = RefLog(repo.head);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
repo.head.free();
|
||||
reflog.free();
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
group('RefLog', () {
|
||||
test('initializes successfully', () {
|
||||
expect(reflog, isA<RefLog>());
|
||||
});
|
||||
|
|
|
@ -269,6 +269,41 @@ void main() {
|
|||
expect(repo.isBranchUnborn, true);
|
||||
});
|
||||
});
|
||||
|
||||
group('createBlob', () {
|
||||
const newBlobContent = 'New blob\n';
|
||||
|
||||
test('successfully creates new blob', () {
|
||||
final oid = repo.createBlob(newBlobContent);
|
||||
final newBlob = Blob.lookup(repo, oid);
|
||||
|
||||
expect(newBlob, isA<Blob>());
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'successfully creates new blob from file at provided relative path',
|
||||
() {
|
||||
final oid = repo.createBlobFromWorkdir('feature_file');
|
||||
final newBlob = Blob.lookup(repo, oid);
|
||||
|
||||
expect(newBlob, isA<Blob>());
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
test('successfully creates new blob from file at provided path', () {
|
||||
final outsideFile =
|
||||
File('${Directory.current.absolute.path}/test/blob_test.dart');
|
||||
final oid = repo.createBlobFromDisk(outsideFile.path);
|
||||
final newBlob = Blob.lookup(repo, oid);
|
||||
|
||||
expect(newBlob, isA<Blob>());
|
||||
|
||||
newBlob.free();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,25 +3,24 @@ import 'package:libgit2dart/libgit2dart.dart';
|
|||
|
||||
void main() {
|
||||
late Signature signature;
|
||||
const name = 'Some Name';
|
||||
const email = 'some@email.com';
|
||||
const time = 1234567890;
|
||||
const offset = 0;
|
||||
|
||||
setUp(() {
|
||||
signature = Signature.create(
|
||||
name: name,
|
||||
email: email,
|
||||
time: time,
|
||||
offset: offset,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
signature.free();
|
||||
});
|
||||
group('Signature', () {
|
||||
const name = 'Some Name';
|
||||
const email = 'some@email.com';
|
||||
const time = 1234567890;
|
||||
const offset = 0;
|
||||
|
||||
setUp(() {
|
||||
signature = Signature.create(
|
||||
name: name,
|
||||
email: email,
|
||||
time: time,
|
||||
offset: offset,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
signature.free();
|
||||
});
|
||||
|
||||
test('successfully creates with provided time and offset', () {
|
||||
expect(signature, isA<Signature>());
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue