mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(repository)!: add more aliases for api methods
BREAKING CHANGE: Make repository entry point for most operations
This commit is contained in:
parent
9205a3ad82
commit
3a0fa75929
51 changed files with 1380 additions and 1062 deletions
|
@ -11,16 +11,16 @@ void main() {
|
|||
const blobContent = 'Feature edit\n';
|
||||
const newBlobContent = 'New blob\n';
|
||||
|
||||
setUp(() async {
|
||||
tmpDir = await setupRepo(Directory('test/assets/testrepo/'));
|
||||
setUp(() {
|
||||
tmpDir = setupRepo(Directory('test/assets/testrepo/'));
|
||||
repo = Repository.open(tmpDir.path);
|
||||
blob = Blob.lookup(repo: repo, sha: blobSHA);
|
||||
blob = repo.lookupBlob(repo[blobSHA]);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tearDown(() {
|
||||
blob.free();
|
||||
repo.free();
|
||||
await tmpDir.delete(recursive: true);
|
||||
tmpDir.deleteSync(recursive: true);
|
||||
});
|
||||
|
||||
group('Blob', () {
|
||||
|
@ -36,8 +36,8 @@ void main() {
|
|||
});
|
||||
|
||||
test('successfully creates new blob', () {
|
||||
final oid = Blob.create(repo: repo, content: newBlobContent);
|
||||
final newBlob = Blob.lookup(repo: repo, sha: oid.sha);
|
||||
final oid = repo.createBlob(newBlobContent);
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
|
||||
expect(newBlob.id.sha, '18fdaeef018e57a92bcad2d4a35b577f34089af6');
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -49,11 +49,8 @@ void main() {
|
|||
|
||||
test('successfully creates new blob from file at provided relative path',
|
||||
() {
|
||||
final oid = Blob.createFromWorkdir(
|
||||
repo: repo,
|
||||
relativePath: 'feature_file',
|
||||
);
|
||||
final newBlob = Blob.lookup(repo: repo, sha: oid.sha);
|
||||
final oid = repo.createBlobFromWorkdir('feature_file');
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
|
||||
expect(newBlob.id.sha, blobSHA);
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -65,10 +62,7 @@ void main() {
|
|||
|
||||
test('throws when creating new blob from invalid path', () {
|
||||
expect(
|
||||
() => Blob.createFromWorkdir(
|
||||
repo: repo,
|
||||
relativePath: 'invalid/path.txt',
|
||||
),
|
||||
() => repo.createBlobFromWorkdir('invalid/path.txt'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -79,10 +73,7 @@ void main() {
|
|||
final outsideFile =
|
||||
File('${Directory.current.absolute.path}/test/blob_test.dart');
|
||||
expect(
|
||||
() => Blob.createFromWorkdir(
|
||||
repo: repo,
|
||||
relativePath: outsideFile.path,
|
||||
),
|
||||
() => repo.createBlobFromWorkdir(outsideFile.path),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
@ -90,8 +81,8 @@ void main() {
|
|||
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: repo, path: outsideFile.path);
|
||||
final newBlob = Blob.lookup(repo: repo, sha: oid.sha);
|
||||
final oid = repo.createBlobFromDisk(outsideFile.path);
|
||||
final newBlob = repo.lookupBlob(oid);
|
||||
|
||||
expect(newBlob, isA<Blob>());
|
||||
expect(newBlob.isBinary, false);
|
||||
|
@ -101,8 +92,6 @@ void main() {
|
|||
|
||||
group('diff', () {
|
||||
const path = 'feature_file';
|
||||
const oldBlobSha = 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391';
|
||||
const newBlobSha = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc';
|
||||
const blobPatch = """
|
||||
diff --git a/feature_file b/feature_file
|
||||
index e69de29..9c78c21 100644
|
||||
|
@ -120,8 +109,12 @@ index e69de29..0000000
|
|||
+++ /dev/null
|
||||
""";
|
||||
test('successfully creates from blobs', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final b = repo[newBlobSha] as Blob;
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final b = repo.lookupBlob(
|
||||
repo['9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc'],
|
||||
);
|
||||
final patch = repo.diffBlobs(
|
||||
a: a,
|
||||
b: b,
|
||||
|
@ -135,7 +128,9 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('successfully creates from one blob (delete)', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final patch = a.diff(
|
||||
newBlob: null,
|
||||
oldAsPath: path,
|
||||
|
@ -148,7 +143,9 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('successfully creates from blob and buffer', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final patch = Patch.createFrom(
|
||||
a: a,
|
||||
b: 'Feature edit\n',
|
||||
|
@ -162,7 +159,9 @@ index e69de29..0000000
|
|||
});
|
||||
|
||||
test('successfully creates from blob and buffer (delete)', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final a = repo.lookupBlob(
|
||||
repo['e69de29bb2d1d6434b8b29ae775ad8c2e48c5391'],
|
||||
);
|
||||
final patch = Patch.createFrom(
|
||||
a: a,
|
||||
b: null,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue