mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -04:00
feat(rebase)!: add more bindings and API methods (#27)
This commit is contained in:
parent
fe570a6990
commit
fb4694cf06
3 changed files with 171 additions and 18 deletions
|
@ -50,11 +50,45 @@ Pointer<git_rebase> init({
|
|||
}
|
||||
}
|
||||
|
||||
/// Opens an existing rebase that was previously started by either an
|
||||
/// invocation of [init] or by another client.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_rebase> open(Pointer<git_repository> repo) {
|
||||
final out = calloc<Pointer<git_rebase>>();
|
||||
final opts = calloc<git_rebase_options>();
|
||||
libgit2.git_rebase_options_init(opts, GIT_REBASE_OPTIONS_VERSION);
|
||||
|
||||
final error = libgit2.git_rebase_open(out, repo, opts);
|
||||
|
||||
if (error < 0) {
|
||||
calloc.free(out);
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out.value;
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the count of rebase operations that are to be applied.
|
||||
int operationsCount(Pointer<git_rebase> rebase) {
|
||||
return libgit2.git_rebase_operation_entrycount(rebase);
|
||||
}
|
||||
|
||||
/// Gets the rebase operation specified by the given index.
|
||||
Pointer<git_rebase_operation> getOperationByIndex({
|
||||
required Pointer<git_rebase> rebase,
|
||||
required int index,
|
||||
}) {
|
||||
return libgit2.git_rebase_operation_byindex(rebase, index);
|
||||
}
|
||||
|
||||
/// Gets the index of the rebase operation that is currently being applied. If
|
||||
/// the first operation has not yet been applied (because you have called [init]
|
||||
/// but not yet [next]) then this returns `-1`.
|
||||
int currentOperation(Pointer<git_rebase> rebase) {
|
||||
return libgit2.git_rebase_operation_current(rebase);
|
||||
}
|
||||
|
||||
/// Performs the next rebase operation and returns the information about it.
|
||||
/// If the operation is one that applies a patch (which is any operation except
|
||||
/// GIT_REBASE_OPERATION_EXEC) then the patch will be applied and the index and
|
||||
|
@ -75,7 +109,7 @@ Pointer<git_rebase_operation> next(Pointer<git_rebase> rebase) {
|
|||
}
|
||||
|
||||
/// Commits the current patch. You must have resolved any conflicts that were
|
||||
/// introduced during the patch application from the `next()` invocation.
|
||||
/// introduced during the patch application from the [next] invocation.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void commit({
|
||||
|
@ -113,5 +147,24 @@ void finish(Pointer<git_rebase> rebase) =>
|
|||
/// working directory to their state before rebase began.
|
||||
void abort(Pointer<git_rebase> rebase) => libgit2.git_rebase_abort(rebase);
|
||||
|
||||
/// Gets the original HEAD id for merge rebases.
|
||||
Pointer<git_oid> origHeadOid(Pointer<git_rebase> rebase) =>
|
||||
libgit2.git_rebase_orig_head_id(rebase);
|
||||
|
||||
/// Gets the original HEAD ref name for merge rebases.
|
||||
String origHeadName(Pointer<git_rebase> rebase) {
|
||||
final result = libgit2.git_rebase_orig_head_name(rebase);
|
||||
return result == nullptr ? '' : result.cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Gets the onto id for merge rebases.
|
||||
Pointer<git_oid> ontoOid(Pointer<git_rebase> rebase) =>
|
||||
libgit2.git_rebase_onto_id(rebase);
|
||||
|
||||
/// Gets the onto ref name for merge rebases.
|
||||
String ontoName(Pointer<git_rebase> rebase) {
|
||||
return libgit2.git_rebase_onto_name(rebase).cast<Utf8>().toDartString();
|
||||
}
|
||||
|
||||
/// Free memory allocated for rebase object.
|
||||
void free(Pointer<git_rebase> rebase) => libgit2.git_rebase_free(rebase);
|
||||
|
|
|
@ -34,12 +34,62 @@ class Rebase {
|
|||
);
|
||||
}
|
||||
|
||||
/// Opens an existing rebase that was previously started by either an
|
||||
/// invocation of [Rebase.init] or by another client.
|
||||
///
|
||||
/// **IMPORTANT**: Should be freed to release allocated memory.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Rebase.open(Repository repo) {
|
||||
_rebasePointer = bindings.open(repo.pointer);
|
||||
}
|
||||
|
||||
/// Pointer to memory address for allocated rebase object.
|
||||
late final Pointer<git_rebase> _rebasePointer;
|
||||
|
||||
/// Number of rebase operations that are to be applied.
|
||||
int get operationsCount {
|
||||
return bindings.operationsCount(_rebasePointer);
|
||||
/// List of operations that are to be applied.
|
||||
List<RebaseOperation> get operations {
|
||||
final result = <RebaseOperation>[];
|
||||
final operationsCount = bindings.operationsCount(_rebasePointer);
|
||||
|
||||
for (var i = 0; i < operationsCount; i++) {
|
||||
final operation = bindings.getOperationByIndex(
|
||||
rebase: _rebasePointer,
|
||||
index: i,
|
||||
);
|
||||
result.add(RebaseOperation(operation));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// Index of the rebase operation that is currently being applied. If the
|
||||
/// first operation has not yet been applied (because you have called
|
||||
/// [Rebase.init] but not yet [next]) then this returns `-1`.
|
||||
int get currentOperation {
|
||||
return bindings.currentOperation(_rebasePointer);
|
||||
}
|
||||
|
||||
/// Original HEAD oid for merge rebases.
|
||||
Oid get origHeadOid {
|
||||
return Oid.fromRaw(bindings.origHeadOid(_rebasePointer).ref);
|
||||
}
|
||||
|
||||
/// Original HEAD ref name for merge rebases.
|
||||
///
|
||||
/// Returns empty string if no information available.
|
||||
String get origHeadName {
|
||||
return bindings.origHeadName(_rebasePointer);
|
||||
}
|
||||
|
||||
/// Onto oid for merge rebases.
|
||||
Oid get ontoOid {
|
||||
return Oid.fromRaw(bindings.ontoOid(_rebasePointer).ref);
|
||||
}
|
||||
|
||||
/// Onto ref name for merge rebases.
|
||||
String get ontoName {
|
||||
return bindings.ontoName(_rebasePointer);
|
||||
}
|
||||
|
||||
/// Performs the next rebase operation and returns the information about it.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue