feat(diff): return list of patches

This commit is contained in:
Aleksey Kulikov 2021-09-20 11:02:44 +03:00
parent 677457279d
commit 6845286af2
2 changed files with 25 additions and 0 deletions

View file

@ -40,6 +40,16 @@ class Diff {
return deltas;
}
/// Returns a list of [Patch]es.
List<Patch> get patches {
final length = bindings.length(_diffPointer);
var patches = <Patch>[];
for (var i = 0; i < length; i++) {
patches.add(Patch.fromDiff(this, i));
}
return patches;
}
/// Returns a patch diff string.
String get patch {
final length = bindings.length(_diffPointer);

View file

@ -281,6 +281,21 @@ index e69de29..c217c63 100644
index.free();
});
test('returns deltas', () {
final index = repo.index;
final diff = index.diffToWorkdir();
final patches = diff.patches;
expect(patches.length, 8);
expect(patches.first.delta.status, GitDelta.deleted);
for (var p in patches) {
p.free();
}
diff.free();
index.free();
});
test('returns stats', () {
final index = repo.index;
final diff = index.diffToWorkdir();