mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(reference): add more bindings and API methods (#28)
This commit is contained in:
parent
fb4694cf06
commit
ff2dd8b408
3 changed files with 55 additions and 0 deletions
|
@ -157,6 +157,25 @@ bool hasLog({
|
||||||
return result == 1 || false;
|
return result == 1 || false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ensure there is a reflog for a particular reference.
|
||||||
|
///
|
||||||
|
/// Make sure that successive updates to the reference will append to its log.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void ensureLog({
|
||||||
|
required Pointer<git_repository> repoPointer,
|
||||||
|
required String refName,
|
||||||
|
}) {
|
||||||
|
final refNameC = refName.toNativeUtf8().cast<Int8>();
|
||||||
|
final error = libgit2.git_reference_ensure_log(repoPointer, refNameC);
|
||||||
|
|
||||||
|
calloc.free(refNameC);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Check if a reference is a local branch.
|
/// Check if a reference is a local branch.
|
||||||
bool isBranch(Pointer<git_reference> ref) {
|
bool isBranch(Pointer<git_reference> ref) {
|
||||||
return libgit2.git_reference_is_branch(ref) == 1 || false;
|
return libgit2.git_reference_is_branch(ref) == 1 || false;
|
||||||
|
@ -410,5 +429,12 @@ Pointer<git_object> peel({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a copy of an existing reference.
|
||||||
|
Pointer<git_reference> duplicate(Pointer<git_reference> source) {
|
||||||
|
final out = calloc<Pointer<git_reference>>();
|
||||||
|
libgit2.git_reference_dup(out, source);
|
||||||
|
return out.value;
|
||||||
|
}
|
||||||
|
|
||||||
/// Free the given reference.
|
/// Free the given reference.
|
||||||
void free(Pointer<git_reference> ref) => libgit2.git_reference_free(ref);
|
void free(Pointer<git_reference> ref) => libgit2.git_reference_free(ref);
|
||||||
|
|
|
@ -139,6 +139,11 @@ class Reference {
|
||||||
refdb_bindings.free(refdb);
|
refdb_bindings.free(refdb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Creates a copy of an existing reference.
|
||||||
|
///
|
||||||
|
/// **IMPORTANT**: Should be freed to release allocated memory.
|
||||||
|
Reference duplicate() => Reference(bindings.duplicate(_refPointer));
|
||||||
|
|
||||||
/// Type of the reference.
|
/// Type of the reference.
|
||||||
ReferenceType get type {
|
ReferenceType get type {
|
||||||
return bindings.referenceType(_refPointer) == 1
|
return bindings.referenceType(_refPointer) == 1
|
||||||
|
@ -242,6 +247,17 @@ class Reference {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Ensures there is a reflog for a particular reference.
|
||||||
|
///
|
||||||
|
/// Makes sure that successive updates to the reference will append to its
|
||||||
|
/// log.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void ensureLog() {
|
||||||
|
final owner = bindings.owner(_refPointer);
|
||||||
|
bindings.ensureLog(repoPointer: owner, refName: name);
|
||||||
|
}
|
||||||
|
|
||||||
/// [RefLog] object.
|
/// [RefLog] object.
|
||||||
///
|
///
|
||||||
/// **IMPORTANT**: Should be freed to release allocated memory.
|
/// **IMPORTANT**: Should be freed to release allocated memory.
|
||||||
|
|
|
@ -128,6 +128,19 @@ void main() {
|
||||||
ref.free();
|
ref.free();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('duplicates existing reference', () {
|
||||||
|
expect(repo.references.length, 6);
|
||||||
|
|
||||||
|
final ref = repo.lookupReference('refs/heads/master');
|
||||||
|
final duplicate = ref.duplicate();
|
||||||
|
|
||||||
|
expect(repo.references.length, 6);
|
||||||
|
expect(duplicate, equals(ref));
|
||||||
|
|
||||||
|
duplicate.free();
|
||||||
|
ref.free();
|
||||||
|
});
|
||||||
|
|
||||||
group('create direct', () {
|
group('create direct', () {
|
||||||
test('successfully creates with Oid as target', () {
|
test('successfully creates with Oid as target', () {
|
||||||
final ref = repo.lookupReference('refs/heads/master');
|
final ref = repo.lookupReference('refs/heads/master');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue