mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(index): add ability to create diff between two indexes (#34)
This commit is contained in:
parent
cc78e7945f
commit
6fe24dcb65
3 changed files with 139 additions and 15 deletions
|
@ -71,6 +71,21 @@ void main() {
|
|||
'subdir/modified_file',
|
||||
];
|
||||
|
||||
const indexToIndex = [
|
||||
'current_file',
|
||||
'file_deleted',
|
||||
'modified_file',
|
||||
'staged_changes',
|
||||
'staged_changes_file_deleted',
|
||||
'staged_changes_file_modified',
|
||||
'staged_new',
|
||||
'staged_new_file_deleted',
|
||||
'staged_new_file_modified',
|
||||
'subdir/current_file',
|
||||
'subdir/deleted_file',
|
||||
'subdir/modified_file',
|
||||
];
|
||||
|
||||
const patchText = """
|
||||
diff --git a/subdir/modified_file b/subdir/modified_file
|
||||
index e69de29..c217c63 100644
|
||||
|
@ -237,6 +252,45 @@ index e69de29..c217c63 100644
|
|||
head.free();
|
||||
});
|
||||
|
||||
test(
|
||||
'throws when trying to diff between tree and workdir with index and '
|
||||
'error occurs', () {
|
||||
expect(
|
||||
() => Diff.treeToWorkdirWithIndex(
|
||||
repo: Repository(nullptr),
|
||||
tree: null,
|
||||
),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('returns diff between index and index', () {
|
||||
final index = repo.index;
|
||||
final emptyIndex = Index.newInMemory();
|
||||
|
||||
final diff = index.diffToIndex(index: emptyIndex);
|
||||
|
||||
expect(diff.length, 12);
|
||||
for (var i = 0; i < diff.deltas.length; i++) {
|
||||
expect(diff.deltas[i].newFile.path, indexToIndex[i]);
|
||||
}
|
||||
|
||||
index.free();
|
||||
emptyIndex.free();
|
||||
});
|
||||
|
||||
test('throws when trying to diff between index and index and error occurs',
|
||||
() {
|
||||
final index = repo.index;
|
||||
|
||||
expect(
|
||||
() => index.diffToIndex(index: Index(nullptr)),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
index.free();
|
||||
});
|
||||
|
||||
test('merges diffs', () {
|
||||
final head = repo.head;
|
||||
final commit = repo.lookupCommit(head.target);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue