mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(revwalk): add more bindings and API methods (#31)
This commit is contained in:
parent
74a20a9cf2
commit
f1b84efc81
3 changed files with 312 additions and 0 deletions
|
@ -94,6 +94,81 @@ void main() {
|
|||
walker.free();
|
||||
});
|
||||
|
||||
test('adds matching references for traversal with provided glob', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.pushGlob('heads');
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 7);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test("adds repository's head for traversal", () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.pushHead();
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('adds reference for traversal with provided name', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.pushReference('refs/heads/master');
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add reference for traversal with invalid name',
|
||||
() {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.pushReference('invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('adds range for traversal', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.pushRange('HEAD..@{-1}');
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 1);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to add invalid range for traversal', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.pushRange('HEAD..invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('successfully hides commit and its ancestors', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
|
@ -120,6 +195,76 @@ void main() {
|
|||
walker.free();
|
||||
});
|
||||
|
||||
test('hides oids of references for provided glob pattern', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.pushGlob('heads');
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 7);
|
||||
|
||||
walker.pushGlob('heads');
|
||||
walker.hideGlob('*master');
|
||||
final hiddenCommits = walker.walk();
|
||||
expect(hiddenCommits.length, 1);
|
||||
|
||||
hiddenCommits[0].free();
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('hides head', () {
|
||||
final head = repo.head;
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.push(head.target);
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
walker.push(head.target);
|
||||
walker.hideHead();
|
||||
final hiddenCommits = walker.walk();
|
||||
expect(hiddenCommits.length, 0);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
head.free();
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('hides oids of reference with provided name', () {
|
||||
final head = repo.head;
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
walker.push(head.target);
|
||||
final commits = walker.walk();
|
||||
expect(commits.length, 6);
|
||||
|
||||
walker.push(head.target);
|
||||
walker.hideReference('refs/heads/master');
|
||||
final hiddenCommits = walker.walk();
|
||||
expect(hiddenCommits.length, 0);
|
||||
|
||||
for (final c in commits) {
|
||||
c.free();
|
||||
}
|
||||
head.free();
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('throws when trying to hide oids of reference with invalid name', () {
|
||||
final walker = RevWalk(repo);
|
||||
|
||||
expect(
|
||||
() => walker.hideReference('invalid'),
|
||||
throwsA(isA<LibGit2Error>()),
|
||||
);
|
||||
|
||||
walker.free();
|
||||
});
|
||||
|
||||
test('successfully resets walker', () {
|
||||
final walker = RevWalk(repo);
|
||||
final start = Oid.fromSHA(repo: repo, sha: log.first);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue