mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
add name_to_id binding and headCommit to repo
- implemented git_reference_name_to_id binding - created repository.headCommit getter
This commit is contained in:
parent
b66662f33c
commit
35afc87b58
5 changed files with 58 additions and 0 deletions
|
@ -449,5 +449,31 @@ Pointer<git_reference> duplicate(Pointer<git_reference> source) {
|
|||
return result;
|
||||
}
|
||||
|
||||
/// Lookup a reference by name and resolve immediately to OID.
|
||||
///
|
||||
/// This function provides a quick way to resolve a reference name straight
|
||||
/// through to the object id that it refers to. This avoids having to
|
||||
/// allocate or free any `git_reference` objects for simple situations.
|
||||
///
|
||||
/// The name will be checked for validity.
|
||||
/// See [createSymbolic] for rules about valid names.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_oid> nameToId({
|
||||
required Pointer<git_repository> repoPointer,
|
||||
required String refName,
|
||||
}) {
|
||||
final result = calloc<git_oid>();
|
||||
final nameC = refName.toChar();
|
||||
|
||||
final error = libgit2.git_reference_name_to_id(result, repoPointer, nameC);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// Free the given reference.
|
||||
void free(Pointer<git_reference> ref) => libgit2.git_reference_free(ref);
|
||||
|
|
|
@ -191,6 +191,24 @@ class Reference extends Equatable {
|
|||
bindings.ensureLog(repoPointer: repo.pointer, refName: refName);
|
||||
}
|
||||
|
||||
/// Lookup a reference by name and resolve immediately to OID.
|
||||
///
|
||||
/// This function provides a quick way to resolve a reference name straight
|
||||
/// through to the object id that it refers to. This avoids having to
|
||||
/// allocate or free any `git_reference` objects for simple situations.
|
||||
///
|
||||
/// The name will be checked for validity.
|
||||
/// See [createSymbolic] for rules about valid names.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
static Oid nameToId({
|
||||
required Repository repo,
|
||||
required String refName,
|
||||
}) {
|
||||
final res = bindings.nameToId(repoPointer: repo.pointer, refName: refName);
|
||||
return Oid(res);
|
||||
}
|
||||
|
||||
/// Creates a copy of an existing reference.
|
||||
Reference duplicate() => Reference(bindings.duplicate(_refPointer));
|
||||
|
||||
|
|
|
@ -339,6 +339,11 @@ class Repository extends Equatable {
|
|||
);
|
||||
}
|
||||
|
||||
/// Retrieve the commit that HEAD is currently pointing to
|
||||
Commit get headCommit {
|
||||
return Commit.lookup(repo: this, oid: head.target);
|
||||
}
|
||||
|
||||
/// Removes all the metadata associated with an ongoing command like
|
||||
/// merge, revert, cherry-pick, etc. For example: MERGE_HEAD, MERGE_MSG, etc.
|
||||
///
|
||||
|
|
|
@ -530,6 +530,11 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
test('get oid by name', () {
|
||||
final oid = Reference.nameToId(repo: repo, refName: 'HEAD');
|
||||
expect(oid, repo.head.target);
|
||||
});
|
||||
|
||||
test('manually releases allocated memory', () {
|
||||
final ref = Reference.lookup(repo: repo, name: 'refs/heads/master');
|
||||
expect(() => ref.free(), returnsNormally);
|
||||
|
|
|
@ -246,6 +246,10 @@ void main() {
|
|||
expect(() => repo.free(), returnsNormally);
|
||||
});
|
||||
|
||||
test('get head commit', () {
|
||||
expect(repo.headCommit.oid.sha, lastCommit);
|
||||
});
|
||||
|
||||
test('returns string representation of Repository object', () {
|
||||
expect(repo.toString(), contains('Repository{'));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue