mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor: pass sha hex string instead of Oid as argument
This commit is contained in:
parent
2cf974c624
commit
fb69de66d2
5 changed files with 25 additions and 19 deletions
|
@ -350,14 +350,17 @@ class Repository {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the list of commits starting from provided [oid].
|
||||
/// Returns the list of commits starting from provided [sha] hex string.
|
||||
///
|
||||
/// If [sorting] isn't provided default will be used (reverse chronological order, like in git).
|
||||
List<Commit> log(Oid oid, [List<GitSort>? sorting]) {
|
||||
List<Commit> log(String sha, [List<GitSort>? sorting]) {
|
||||
final oid = Oid.fromSHA(this, sha);
|
||||
final walker = RevWalk(this);
|
||||
|
||||
walker.sorting(sorting ?? [GitSort.none]);
|
||||
walker.push(oid);
|
||||
final result = walker.walk();
|
||||
|
||||
walker.free();
|
||||
|
||||
return result;
|
||||
|
@ -397,11 +400,13 @@ class Repository {
|
|||
/// Finds a merge base between two commits.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Oid mergeBase(Oid one, Oid two) {
|
||||
Oid mergeBase(String one, String two) {
|
||||
final oidOne = Oid.fromSHA(this, one);
|
||||
final oidTwo = Oid.fromSHA(this, two);
|
||||
return Oid(merge_bindings.mergeBase(
|
||||
_repoPointer,
|
||||
one.pointer,
|
||||
two.pointer,
|
||||
oidOne.pointer,
|
||||
oidTwo.pointer,
|
||||
));
|
||||
}
|
||||
|
||||
|
@ -436,7 +441,7 @@ class Repository {
|
|||
/// Throws a [LibGit2Error] if error occured.
|
||||
Oid createTag({
|
||||
required String tagName,
|
||||
required Oid target,
|
||||
required String target,
|
||||
required GitObject targetType,
|
||||
required Signature tagger,
|
||||
required String message,
|
||||
|
|
|
@ -48,15 +48,16 @@ class Tag {
|
|||
static Oid create({
|
||||
required Repository repository,
|
||||
required String tagName,
|
||||
required Oid target,
|
||||
required String target,
|
||||
required GitObject targetType,
|
||||
required Signature tagger,
|
||||
required String message,
|
||||
bool force = false,
|
||||
}) {
|
||||
final targetOid = Oid.fromSHA(repository, target);
|
||||
final object = object_bindings.lookup(
|
||||
repository.pointer,
|
||||
target.pointer,
|
||||
targetOid.pointer,
|
||||
targetType.value,
|
||||
);
|
||||
final result = bindings.create(
|
||||
|
|
|
@ -188,8 +188,7 @@ void main() {
|
|||
'6cbc22e509d72758ab4c8d9f287ea846b90c448b',
|
||||
'f17d0d48eae3aa08cecf29128a35e310c97b3521',
|
||||
];
|
||||
final start = Oid.fromSHA(repo, lastCommit);
|
||||
final commits = repo.log(start);
|
||||
final commits = repo.log(lastCommit);
|
||||
|
||||
for (var i = 0; i < commits.length; i++) {
|
||||
expect(commits[i].id.sha, log[i]);
|
||||
|
@ -305,15 +304,14 @@ void main() {
|
|||
});
|
||||
});
|
||||
|
||||
test('successfully creates tag with provided Oid', () {
|
||||
test('successfully creates tag with provided sha', () {
|
||||
final signature = Signature.create(
|
||||
name: 'Author',
|
||||
email: 'author@email.com',
|
||||
time: 1234,
|
||||
);
|
||||
const tagName = 'tag';
|
||||
final target =
|
||||
Oid.fromSHA(repo, 'f17d0d48eae3aa08cecf29128a35e310c97b3521');
|
||||
const target = 'f17d0d48eae3aa08cecf29128a35e310c97b3521';
|
||||
const message = 'init tag\n';
|
||||
|
||||
final oid = Tag.create(
|
||||
|
@ -333,7 +331,7 @@ void main() {
|
|||
expect(newTag.name, tagName);
|
||||
expect(newTag.message, message);
|
||||
expect(tagger, signature);
|
||||
expect(newTagTarget.id, target);
|
||||
expect(newTagTarget.id.sha, target);
|
||||
|
||||
newTag.free();
|
||||
newTagTarget.free();
|
||||
|
|
|
@ -99,7 +99,10 @@ void main() {
|
|||
expect(revspec.from.id.sha, headSHA);
|
||||
expect(revspec.to?.id.sha, '5aecfa0fb97eadaac050ccb99f03c3fb65460ad4');
|
||||
expect(revspec.flags, GitRevParse.mergeBase);
|
||||
expect(repo.mergeBase(revspec.from.id, revspec.to!.id), isA<Oid>());
|
||||
expect(
|
||||
repo.mergeBase(revspec.from.id.sha, revspec.to!.id.sha),
|
||||
isA<Oid>(),
|
||||
);
|
||||
|
||||
revspec.from.free();
|
||||
revspec.to?.free();
|
||||
|
|
|
@ -29,7 +29,7 @@ void main() {
|
|||
});
|
||||
|
||||
group('Tag', () {
|
||||
test('successfully initializes tag from provided Oid', () {
|
||||
test('successfully initializes tag from provided sha', () {
|
||||
expect(tag, isA<Tag>());
|
||||
});
|
||||
|
||||
|
@ -60,8 +60,7 @@ void main() {
|
|||
time: 1234,
|
||||
);
|
||||
const tagName = 'tag';
|
||||
final target =
|
||||
Oid.fromSHA(repo, 'f17d0d48eae3aa08cecf29128a35e310c97b3521');
|
||||
final target = 'f17d0d48eae3aa08cecf29128a35e310c97b3521';
|
||||
const message = 'init tag\n';
|
||||
|
||||
final oid = Tag.create(
|
||||
|
@ -81,7 +80,7 @@ void main() {
|
|||
expect(newTag.name, tagName);
|
||||
expect(newTag.message, message);
|
||||
expect(tagger, signature);
|
||||
expect(newTagTarget.id, target);
|
||||
expect(newTagTarget.id.sha, target);
|
||||
|
||||
newTag.free();
|
||||
newTagTarget.free();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue