mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(patch): add bindings and api
This commit is contained in:
parent
f7f4a395c0
commit
344dba60e9
11 changed files with 1087 additions and 47 deletions
|
@ -96,5 +96,82 @@ void main() {
|
|||
|
||||
newBlob.free();
|
||||
});
|
||||
|
||||
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
|
||||
--- a/feature_file
|
||||
+++ b/feature_file
|
||||
@@ -0,0 +1 @@
|
||||
+Feature edit
|
||||
""";
|
||||
|
||||
const blobPatchDelete = """
|
||||
diff --git a/feature_file b/feature_file
|
||||
deleted file mode 100644
|
||||
index e69de29..0000000
|
||||
--- a/feature_file
|
||||
+++ /dev/null
|
||||
""";
|
||||
test('successfully creates from blobs', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final b = repo[newBlobSha] as Blob;
|
||||
final patch = repo.diffBlobs(
|
||||
a: a,
|
||||
b: b,
|
||||
aPath: path,
|
||||
bPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('successfully creates from one blob (delete)', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final patch = a.diff(
|
||||
newBlob: null,
|
||||
oldAsPath: path,
|
||||
newAsPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('successfully creates from blob and buffer', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final patch = Patch.createFrom(
|
||||
a: a,
|
||||
b: 'Feature edit\n',
|
||||
aPath: path,
|
||||
bPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatch);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
|
||||
test('successfully creates from blob and buffer (delete)', () {
|
||||
final a = repo[oldBlobSha] as Blob;
|
||||
final patch = Patch.createFrom(
|
||||
a: a,
|
||||
b: null,
|
||||
aPath: path,
|
||||
bPath: path,
|
||||
);
|
||||
|
||||
expect(patch.text, blobPatchDelete);
|
||||
|
||||
patch.free();
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue