mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(tree): add bindings and api
This commit is contained in:
parent
6bd04bb09d
commit
84ee4be945
22 changed files with 316 additions and 84 deletions
|
@ -1 +1 @@
|
|||
add another feature file
|
||||
add subdirectory file
|
||||
|
|
Binary file not shown.
|
@ -8,3 +8,4 @@ c68ff54aabf660fcdd9a2838d401583fe31249e3 78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e
|
|||
78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8 fc38877b2552ab554752d9a77e1f48f738cca79b Aleksey Kulikov <skinny.mind@gmail.com> 1626091245 +0300 checkout: moving from master to feature
|
||||
fc38877b2552ab554752d9a77e1f48f738cca79b 5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 Aleksey Kulikov <skinny.mind@gmail.com> 1626091274 +0300 commit: add another feature file
|
||||
5aecfa0fb97eadaac050ccb99f03c3fb65460ad4 78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8 Aleksey Kulikov <skinny.mind@gmail.com> 1626091285 +0300 checkout: moving from feature to master
|
||||
78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8 821ed6e80627b8769d170a293862f9fc60825226 Aleksey Kulikov <skinny.mind@gmail.com> 1630568461 +0300 commit: add subdirectory file
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
0000000000000000000000000000000000000000 f17d0d48eae3aa08cecf29128a35e310c97b3521 Aleksey Kulikov <skinny.mind@gmail.com> 1626090830 +0300 commit (initial): init
|
||||
f17d0d48eae3aa08cecf29128a35e310c97b3521 c68ff54aabf660fcdd9a2838d401583fe31249e3 Aleksey Kulikov <skinny.mind@gmail.com> 1626091171 +0300 commit: add .gitignore
|
||||
c68ff54aabf660fcdd9a2838d401583fe31249e3 78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8 Aleksey Kulikov <skinny.mind@gmail.com> 1626091184 +0300 merge feature: Merge made by the 'recursive' strategy.
|
||||
78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8 821ed6e80627b8769d170a293862f9fc60825226 Aleksey Kulikov <skinny.mind@gmail.com> 1630568461 +0300 commit: add subdirectory file
|
||||
|
|
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
x¥ΞAnΓ Fα®9Εμ#EƒΗ`,EU»ξ)0ό΄ΘΖTGςν›;tϋ<16>^¨¥δNΓθήzΘ;‰ΡΜ°Π<C2B0>‡`ΣδΐΒzIΡLaN"cRΏΎaο4ΉΕ-I™Νζ‰=LΠμ^G-b“…Sώμ?µΡη†υΐE_η–Χϊ¤Η±ζ}Ώξ%οργ»ψΌέC-ο¤°±n΄<6E>n,ΜκU_£<1D> ”<>‘<EFBFBD>s‰Ή!τΪ.Jyƒϊy<>Pα
|
Binary file not shown.
|
@ -1 +1 @@
|
|||
78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8
|
||||
821ed6e80627b8769d170a293862f9fc60825226
|
||||
|
|
0
test/assets/testrepo/.gitdir/refs/tags/empty_marker
Normal file
0
test/assets/testrepo/.gitdir/refs/tags/empty_marker
Normal file
0
test/assets/testrepo/dir/dir_file.txt
Normal file
0
test/assets/testrepo/dir/dir_file.txt
Normal file
|
@ -32,7 +32,7 @@ void main() {
|
|||
const featureFileSha = '9c78c21d6680a7ffebc76f7ac68cacc11d8f48bc';
|
||||
|
||||
test('returns number of entries', () {
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
});
|
||||
|
||||
test('returns mode of index entry', () {
|
||||
|
@ -40,7 +40,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns index entry at provided position', () {
|
||||
expect(index[2].path, 'file');
|
||||
expect(index[2].path, 'feature_file');
|
||||
expect(index['file'].sha, fileSha);
|
||||
});
|
||||
|
||||
|
@ -74,7 +74,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('clears the contents', () {
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
index.clear();
|
||||
expect(index.count, 0);
|
||||
});
|
||||
|
@ -85,13 +85,13 @@ void main() {
|
|||
|
||||
index.add(entry);
|
||||
expect(index['file'].sha, fileSha);
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
});
|
||||
|
||||
test('successfully adds with provided path string', () {
|
||||
index.add('file');
|
||||
expect(index['file'].sha, fileSha);
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
});
|
||||
|
||||
test('throws if file not found at provided path', () {
|
||||
|
@ -134,7 +134,7 @@ void main() {
|
|||
});
|
||||
|
||||
test('writes to disk', () {
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
|
||||
File('$tmpDir/new_file').createSync();
|
||||
|
||||
|
@ -144,7 +144,7 @@ void main() {
|
|||
index.clear();
|
||||
index.read();
|
||||
expect(index['new_file'].path, 'new_file');
|
||||
expect(index.count, 4);
|
||||
expect(index.count, 5);
|
||||
});
|
||||
|
||||
test('removes an entry', () {
|
||||
|
@ -166,18 +166,18 @@ void main() {
|
|||
group('read tree', () {
|
||||
const treeSha = 'df2b8fc99e1c1d4dbc0a854d9f72157f1d6ea078';
|
||||
test('successfully reads with provided SHA hex', () {
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
index.readTree(treeSha);
|
||||
|
||||
expect(index.count, 1);
|
||||
|
||||
// make sure the index is only modified in memory
|
||||
index.read();
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
});
|
||||
|
||||
test('successfully reads with provided short SHA hex', () {
|
||||
expect(index.count, 3);
|
||||
expect(index.count, 4);
|
||||
index.readTree(treeSha.substring(0, 5));
|
||||
|
||||
expect(index.count, 1);
|
||||
|
@ -186,7 +186,7 @@ void main() {
|
|||
|
||||
test('successfully writes tree', () {
|
||||
final oid = index.writeTree();
|
||||
expect(oid.sha, '7796359a96eb722939c24bafdb1afe9f07f2f628');
|
||||
expect(oid.sha, 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import 'package:libgit2dart/libgit2dart.dart';
|
|||
import 'helpers/util.dart';
|
||||
|
||||
void main() {
|
||||
const lastCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||
const newCommit = 'c68ff54aabf660fcdd9a2838d401583fe31249e3';
|
||||
|
||||
group('Reference', () {
|
||||
|
|
|
@ -34,22 +34,19 @@ void main() {
|
|||
});
|
||||
|
||||
test('returns correct number of log entries', () {
|
||||
expect(reflog.count, 3);
|
||||
expect(reflog.count, 4);
|
||||
});
|
||||
|
||||
test('returns the log message', () {
|
||||
final entry = reflog.entryAt(0);
|
||||
expect(
|
||||
entry.message,
|
||||
"merge feature: Merge made by the 'recursive' strategy.",
|
||||
);
|
||||
expect(entry.message, "commit: add subdirectory file");
|
||||
});
|
||||
|
||||
test('returns the committer of the entry', () {
|
||||
final entry = reflog.entryAt(0);
|
||||
expect(entry.committer.name, 'Aleksey Kulikov');
|
||||
expect(entry.committer.email, 'skinny.mind@gmail.com');
|
||||
expect(entry.committer.time, 1626091184);
|
||||
expect(entry.committer.time, 1630568461);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ void main() {
|
|||
});
|
||||
|
||||
group('testrepo', () {
|
||||
const lastCommit = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||
const lastCommit = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||
const featureCommit = '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4';
|
||||
|
||||
final tmpDir = '${Directory.systemTemp.path}/testrepo/';
|
||||
|
@ -181,6 +181,7 @@ void main() {
|
|||
|
||||
test('returns list of commits by walking from provided starting oid', () {
|
||||
const log = [
|
||||
'821ed6e80627b8769d170a293862f9fc60825226',
|
||||
'78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8',
|
||||
'c68ff54aabf660fcdd9a2838d401583fe31249e3',
|
||||
'fc38877b2552ab554752d9a77e1f48f738cca79b',
|
||||
|
|
|
@ -7,8 +7,8 @@ import 'helpers/util.dart';
|
|||
void main() {
|
||||
late Repository repo;
|
||||
final tmpDir = '${Directory.systemTemp.path}/revparse_testrepo/';
|
||||
const headSHA = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||
const parentSHA = 'c68ff54aabf660fcdd9a2838d401583fe31249e3';
|
||||
const headSHA = '821ed6e80627b8769d170a293862f9fc60825226';
|
||||
const parentSHA = '78b8bf123e3952c970ae5c1ce0a3ea1d1336f6e8';
|
||||
|
||||
setUp(() async {
|
||||
if (await Directory(tmpDir).exists()) {
|
||||
|
|
80
test/tree_test.dart
Normal file
80
test/tree_test.dart
Normal file
|
@ -0,0 +1,80 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:test/test.dart';
|
||||
import 'package:libgit2dart/libgit2dart.dart';
|
||||
import 'helpers/util.dart';
|
||||
|
||||
void main() {
|
||||
late Repository repo;
|
||||
late Tree tree;
|
||||
final tmpDir = '${Directory.systemTemp.path}/tree_testrepo/';
|
||||
const treeSHA = 'a8ae3dd59e6e1802c6f78e05e301bfd57c9f334f';
|
||||
const fileSHA = '1377554ebea6f98a2c748183bc5a96852af12ac2';
|
||||
|
||||
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);
|
||||
tree = Tree.lookup(repo, Oid.fromSHA(repo, treeSHA));
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
tree.free();
|
||||
repo.free();
|
||||
await Directory(tmpDir).delete(recursive: true);
|
||||
});
|
||||
|
||||
group('Tree', () {
|
||||
test('successfully initializes tree from provided Oid', () {
|
||||
expect(tree, isA<Tree>());
|
||||
});
|
||||
|
||||
test('returns number of entries', () {
|
||||
expect(tree.entries.length, 4);
|
||||
});
|
||||
|
||||
test('returns sha of tree entry', () {
|
||||
expect(tree.entries.first.id.sha, fileSHA);
|
||||
});
|
||||
|
||||
test('returns name of tree entry', () {
|
||||
expect(tree.entries[0].name, '.gitignore');
|
||||
});
|
||||
|
||||
test('returns filemode of tree entry', () {
|
||||
expect(tree.entries[0].filemode, GitFilemode.blob);
|
||||
});
|
||||
|
||||
test('returns tree entry with provided index position', () {
|
||||
expect(tree[0].id.sha, fileSHA);
|
||||
});
|
||||
|
||||
test('throws when provided index position is outside of valid range', () {
|
||||
expect(() => tree[10], throwsA(isA<RangeError>()));
|
||||
expect(() => tree[-10], throwsA(isA<RangeError>()));
|
||||
});
|
||||
|
||||
test('returns tree entry with provided filename', () {
|
||||
expect(tree['.gitignore'].id.sha, fileSHA);
|
||||
});
|
||||
|
||||
test('throws when nothing found for provided filename', () {
|
||||
expect(() => tree['invalid'], throwsA(isA<ArgumentError>()));
|
||||
});
|
||||
|
||||
test('returns tree entry with provided path to file', () {
|
||||
final entry = tree['dir/dir_file.txt'];
|
||||
expect(entry.id.sha, 'e69de29bb2d1d6434b8b29ae775ad8c2e48c5391');
|
||||
entry.free();
|
||||
});
|
||||
|
||||
test('throws when nothing found for provided path', () {
|
||||
expect(() => tree['invalid/path'], throwsA(isA<LibGit2Error>()));
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue