test: add more tests for throws and their messages

This commit is contained in:
Aleksey Kulikov 2021-10-19 17:16:39 +03:00
parent d6eae1e9ed
commit 127849519d
80 changed files with 2741 additions and 1501 deletions

View file

@ -1,6 +1,5 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import '../error.dart';
import '../util.dart';
import 'libgit2_bindings.dart';
@ -8,8 +7,6 @@ import 'libgit2_bindings.dart';
///
/// Returned value can be either `true`, `false`, `null` (if the attribute was not set at all),
/// or a [String] value, if the attribute was set to an actual string.
///
/// Throws a [LibGit2Error] if error occured.
Object? getAttribute({
required Pointer<git_repository> repoPointer,
required int flags,
@ -19,33 +16,28 @@ Object? getAttribute({
final out = calloc<Pointer<Int8>>();
final pathC = path.toNativeUtf8().cast<Int8>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_attr_get(out, repoPointer, flags, pathC, nameC);
libgit2.git_attr_get(out, repoPointer, flags, pathC, nameC);
calloc.free(pathC);
calloc.free(nameC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
}
final attributeValue = libgit2.git_attr_value(out.value);
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_UNSPECIFIED) {
calloc.free(out);
return null;
} else if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_TRUE) {
}
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_TRUE) {
calloc.free(out);
return true;
} else if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_FALSE) {
}
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_FALSE) {
calloc.free(out);
return false;
} else if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) {
}
if (attributeValue == git_attr_value_t.GIT_ATTR_VALUE_STRING) {
final result = out.value.cast<Utf8>().toDartString();
calloc.free(out);
return result;
} else {
calloc.free(out);
throw Exception('The attribute value from libgit2 is invalid');
}
}

View file

@ -21,17 +21,7 @@ Pointer<git_blame> file({
final out = calloc<Pointer<git_blame>>();
final pathC = path.toNativeUtf8().cast<Int8>();
final options = calloc<git_blame_options>();
final optionsError = libgit2.git_blame_options_init(
options,
GIT_BLAME_OPTIONS_VERSION,
);
if (optionsError < 0) {
calloc.free(out);
calloc.free(pathC);
calloc.free(options);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_blame_options_init(options, GIT_BLAME_OPTIONS_VERSION);
options.ref.flags = flags;

View file

@ -24,32 +24,8 @@ Pointer<git_commit> lookup({
}
}
/// Lookup a commit object from a repository, given a prefix of its identifier (short id).
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_commit> lookupPrefix({
required Pointer<git_repository> repoPointer,
required Pointer<git_oid> oidPointer,
required int len,
}) {
final out = calloc<Pointer<git_commit>>();
final error = libgit2.git_commit_lookup_prefix(
out,
repoPointer,
oidPointer,
len,
);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Creates a git_annotated_commit from the given commit id. The resulting git_annotated_commit
/// must be freed with git_annotated_commit_free.
/// Creates an annotated commit from the given commit id. The resulting annotated commit
/// must be freed with [annotatedFree].
///
/// An annotated commit contains information about how it was looked up, which may be useful
/// for functions like merge or rebase to provide context to the operation. For example, conflict
@ -77,7 +53,7 @@ Pointer<Pointer<git_annotated_commit>> annotatedLookup({
}
}
/// Frees a git_annotated_commit.
/// Frees an annotated commit.
void annotatedFree(Pointer<git_annotated_commit> commit) {
libgit2.git_annotated_commit_free(commit);
}
@ -168,13 +144,7 @@ Pointer<git_oid> parentId({
required Pointer<git_commit> commitPointer,
required int position,
}) {
final parentOid = libgit2.git_commit_parent_id(commitPointer, position);
if (parentOid == nullptr) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return parentOid;
}
return libgit2.git_commit_parent_id(commitPointer, position);
}
/// Get the commit time (i.e. committer time) of a commit.
@ -209,14 +179,7 @@ Pointer<git_index> revertCommit({
}) {
final out = calloc<Pointer<git_index>>();
final opts = calloc<git_merge_options>();
final optsError =
libgit2.git_merge_options_init(opts, GIT_MERGE_OPTIONS_VERSION);
if (optsError < 0) {
calloc.free(out);
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_merge_options_init(opts, GIT_MERGE_OPTIONS_VERSION);
final error = libgit2.git_revert_commit(
out,

View file

@ -77,8 +77,6 @@ Pointer<git_describe_result> workdir({
}
/// Print the describe result to a buffer.
///
/// Throws a [LibGit2Error] if error occured.
String format({
required Pointer<git_describe_result> describeResultPointer,
int? abbreviatedSize,
@ -87,17 +85,11 @@ String format({
}) {
final out = calloc<git_buf>(sizeOf<git_buf>());
final opts = calloc<git_describe_format_options>();
final optsError = libgit2.git_describe_format_options_init(
libgit2.git_describe_format_options_init(
opts,
GIT_DESCRIBE_FORMAT_OPTIONS_VERSION,
);
if (optsError < 0) {
calloc.free(out);
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
if (abbreviatedSize != null) {
opts.ref.abbreviated_size = abbreviatedSize;
}
@ -108,18 +100,14 @@ String format({
opts.ref.dirty_suffix = dirtySuffix.toNativeUtf8().cast<Int8>();
}
final error = libgit2.git_describe_format(out, describeResultPointer, opts);
libgit2.git_describe_format(out, describeResultPointer, opts);
final result = out.ref.ptr.cast<Utf8>().toDartString();
calloc.free(opts);
calloc.free(out);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
final result = out.ref.ptr.cast<Utf8>().toDartString();
calloc.free(out);
return result;
}
return result;
}
/// Free the describe result.
@ -136,15 +124,11 @@ Pointer<git_describe_options> _initOpts({
bool? showCommitOidAsFallback,
}) {
final opts = calloc<git_describe_options>();
final error = libgit2.git_describe_options_init(
libgit2.git_describe_options_init(
opts,
GIT_DESCRIBE_OPTIONS_VERSION,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
if (maxCandidatesTags != null) {
opts.ref.max_candidates_tags = maxCandidatesTags;
}

View file

@ -5,8 +5,6 @@ import 'libgit2_bindings.dart';
import '../util.dart';
/// Create a diff between the repository index and the workdir directory.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> indexToWorkdir({
required Pointer<git_repository> repoPointer,
required Pointer<git_index> indexPointer,
@ -21,16 +19,7 @@ Pointer<git_diff> indexToWorkdir({
interhunkLines: interhunkLines,
);
final error = libgit2.git_diff_index_to_workdir(
out,
repoPointer,
indexPointer,
opts,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_diff_index_to_workdir(out, repoPointer, indexPointer, opts);
calloc.free(opts);
@ -38,8 +27,6 @@ Pointer<git_diff> indexToWorkdir({
}
/// Create a diff between a tree and repository index.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> treeToIndex({
required Pointer<git_repository> repoPointer,
required Pointer<git_tree> treePointer,
@ -55,7 +42,7 @@ Pointer<git_diff> treeToIndex({
interhunkLines: interhunkLines,
);
final error = libgit2.git_diff_tree_to_index(
libgit2.git_diff_tree_to_index(
out,
repoPointer,
treePointer,
@ -63,10 +50,6 @@ Pointer<git_diff> treeToIndex({
opts,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
calloc.free(opts);
return out.value;
@ -166,21 +149,14 @@ void merge({
///
/// This function will only read patch files created by a git implementation, it will not
/// read unified diffs produced by the `diff` program, nor any other types of patch files.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff> parse(String content) {
final out = calloc<Pointer<git_diff>>();
final contentC = content.toNativeUtf8().cast<Int8>();
final error = libgit2.git_diff_from_buffer(out, contentC, content.length);
libgit2.git_diff_from_buffer(out, contentC, content.length);
calloc.free(contentC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
return out.value;
}
/// Transform a diff marking file renames, copies, etc.
@ -200,15 +176,7 @@ void findSimilar({
required int renameLimit,
}) {
final opts = calloc<git_diff_find_options>();
final optsError = libgit2.git_diff_find_options_init(
opts,
GIT_DIFF_FIND_OPTIONS_VERSION,
);
if (optsError < 0) {
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_diff_find_options_init(opts, GIT_DIFF_FIND_OPTIONS_VERSION);
opts.ref.flags = flags;
opts.ref.rename_threshold = renameThreshold;
@ -236,7 +204,7 @@ void findSimilar({
/// and should in fact generate the same IDs as the upstream git project does.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> patchId(Pointer<git_diff> diff) {
Pointer<git_oid> patchOid(Pointer<git_diff> diff) {
final out = calloc<git_oid>();
final error = libgit2.git_diff_patchid(out, diff, nullptr);
@ -249,19 +217,11 @@ Pointer<git_oid> patchId(Pointer<git_diff> diff) {
}
/// Return the diff delta for an entry in the diff list.
///
/// Throws [RangeError] if index out of range.
Pointer<git_diff_delta> getDeltaByIndex({
required Pointer<git_diff> diffPointer,
required int index,
}) {
final result = libgit2.git_diff_get_delta(diffPointer, index);
if (result == nullptr) {
throw RangeError('$index is out of bounds');
} else {
return result;
}
return libgit2.git_diff_get_delta(diffPointer, index);
}
/// Look up the single character abbreviation for a delta status code.
@ -323,19 +283,13 @@ String statsPrint({
}
/// Add patch to buffer.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_buf> addToBuf({
required Pointer<git_patch> patchPointer,
required Pointer<git_buf> bufferPointer,
}) {
final error = libgit2.git_patch_to_buf(bufferPointer, patchPointer);
libgit2.git_patch_to_buf(bufferPointer, patchPointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return bufferPointer;
}
return bufferPointer;
}
/// Apply a diff to the given repository, making changes directly in the working directory,
@ -351,7 +305,7 @@ bool apply({
final opts = calloc<git_apply_options>();
libgit2.git_apply_options_init(opts, GIT_APPLY_OPTIONS_VERSION);
if (check) {
opts.ref.flags = git_apply_flags_t.GIT_APPLY_CHECK;
opts.ref.flags |= git_apply_flags_t.GIT_APPLY_CHECK;
}
final error = libgit2.git_apply(repoPointer, diffPointer, location, opts);
@ -377,18 +331,10 @@ Pointer<git_diff_options> _diffOptionsInit({
required int interhunkLines,
}) {
final opts = calloc<git_diff_options>();
final optsError = libgit2.git_diff_options_init(
opts,
GIT_DIFF_OPTIONS_VERSION,
);
libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION);
if (optsError < 0) {
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
} else {
opts.ref.flags = flags;
opts.ref.context_lines = contextLines;
opts.ref.interhunk_lines = interhunkLines;
return opts;
}
opts.ref.flags = flags;
opts.ref.context_lines = contextLines;
opts.ref.interhunk_lines = interhunkLines;
return opts;
}

View file

@ -14,31 +14,19 @@ import '../util.dart';
/// if it has changed since the last time it was loaded. Purely in-memory index data
/// will be untouched. Be aware: if there are changes on disk, unwritten in-memory changes
/// are discarded.
///
/// Throws a [LibGit2Error] if error occured.
void read({required Pointer<git_index> indexPointer, required bool force}) {
final forceC = force == true ? 1 : 0;
final error = libgit2.git_index_read(indexPointer, forceC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_index_read(indexPointer, forceC);
}
/// Read a tree into the index file with stats.
///
/// The current index contents will be replaced by the specified tree.
///
/// Throws a [LibGit2Error] if error occured.
void readTree({
required Pointer<git_index> indexPointer,
required Pointer<git_tree> treePointer,
}) {
final error = libgit2.git_index_read_tree(indexPointer, treePointer);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_index_read_tree(indexPointer, treePointer);
}
/// Write the index as a tree.
@ -243,15 +231,7 @@ void addAll({
}
/// Write an existing index object from memory back to disk using an atomic file lock.
///
/// Throws a [LibGit2Error] if error occured.
void write(Pointer<git_index> index) {
final error = libgit2.git_index_write(index);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void write(Pointer<git_index> index) => libgit2.git_index_write(index);
/// Remove an entry from the index.
///
@ -272,8 +252,6 @@ void remove({
}
/// Remove all matching index entries.
///
/// Throws a [LibGit2Error] if error occured.
void removeAll({
required Pointer<git_index> indexPointer,
required List<String> pathspec,
@ -290,22 +268,13 @@ void removeAll({
pathspecC.ref.strings = strArray;
pathspecC.ref.count = pathspec.length;
final error = libgit2.git_index_remove_all(
indexPointer,
pathspecC,
nullptr,
nullptr,
);
libgit2.git_index_remove_all(indexPointer, pathspecC, nullptr, nullptr);
calloc.free(pathspecC);
for (final p in pathPointers) {
calloc.free(p);
}
calloc.free(strArray);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Determine if the index contains entries representing file conflicts.
@ -320,15 +289,7 @@ List<Map<String, Pointer<git_index_entry>>> conflictList(
Pointer<git_index> index,
) {
final iterator = calloc<Pointer<git_index_conflict_iterator>>();
final iteratorError = libgit2.git_index_conflict_iterator_new(
iterator,
index,
);
if (iteratorError < 0) {
calloc.free(iterator);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_index_conflict_iterator_new(iterator, index);
var result = <Map<String, Pointer<git_index_entry>>>[];
var error = 0;

View file

@ -1,3 +1,4 @@
// coverage:ignore-file
// AUTO GENERATED FILE, DO NOT EDIT.
//
// Generated by `package:ffigen`.

View file

@ -8,37 +8,23 @@ import '../util.dart';
///
/// This object is empty, so you'll have to add a mailmap file before you can
/// do anything with it. The mailmap must be freed with `free()`.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_mailmap> init() {
final out = calloc<Pointer<git_mailmap>>();
final error = libgit2.git_mailmap_new(out);
libgit2.git_mailmap_new(out);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
return out.value;
}
/// Create a new mailmap instance containing a single mailmap file.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_mailmap> fromBuffer(String buffer) {
final out = calloc<Pointer<git_mailmap>>();
final bufferC = buffer.toNativeUtf8().cast<Int8>();
final error = libgit2.git_mailmap_from_buffer(out, bufferC, buffer.length);
libgit2.git_mailmap_from_buffer(out, bufferC, buffer.length);
calloc.free(bufferC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
return out.value;
}
/// Create a new mailmap instance from a repository, loading mailmap files based
@ -65,8 +51,6 @@ Pointer<git_mailmap> fromRepository(Pointer<git_repository> repo) {
}
/// Resolve a name and email to the corresponding real name and email.
///
/// Throws a [LibGit2Error] if error occured.
List<String> resolve({
required Pointer<git_mailmap> mailmapPointer,
required String name,
@ -76,7 +60,7 @@ List<String> resolve({
final outRealEmail = calloc<Pointer<Int8>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final emailC = email.toNativeUtf8().cast<Int8>();
final error = libgit2.git_mailmap_resolve(
libgit2.git_mailmap_resolve(
outRealName,
outRealEmail,
mailmapPointer,
@ -84,44 +68,25 @@ List<String> resolve({
emailC,
);
if (error < 0) {
calloc.free(outRealName);
calloc.free(outRealEmail);
calloc.free(nameC);
calloc.free(emailC);
throw LibGit2Error(libgit2.git_error_last());
} else {
final realName = outRealName.value.cast<Utf8>().toDartString();
final realEmail = outRealEmail.value.cast<Utf8>().toDartString();
calloc.free(outRealName);
calloc.free(outRealEmail);
calloc.free(nameC);
calloc.free(emailC);
final realName = outRealName.value.cast<Utf8>().toDartString();
final realEmail = outRealEmail.value.cast<Utf8>().toDartString();
calloc.free(outRealName);
calloc.free(outRealEmail);
calloc.free(nameC);
calloc.free(emailC);
return [realName, realEmail];
}
return [realName, realEmail];
}
/// Resolve a signature to use real names and emails with a mailmap.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_signature> resolveSignature({
required Pointer<git_mailmap> mailmapPointer,
required Pointer<git_signature> signaturePointer,
}) {
final out = calloc<Pointer<git_signature>>();
final error = libgit2.git_mailmap_resolve_signature(
out,
mailmapPointer,
signaturePointer,
);
libgit2.git_mailmap_resolve_signature(out, mailmapPointer, signaturePointer);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
return out.value;
}
/// Add a single entry to the given mailmap object. If the entry already exists,
@ -140,7 +105,7 @@ void addEntry({
final replaceNameC = replaceName?.toNativeUtf8().cast<Int8>() ?? nullptr;
final replaceEmailC = replaceEmail.toNativeUtf8().cast<Int8>();
final error = libgit2.git_mailmap_add_entry(
libgit2.git_mailmap_add_entry(
mailmapPointer,
realNameC,
realEmailC,
@ -152,10 +117,6 @@ void addEntry({
calloc.free(realEmailC);
calloc.free(replaceNameC);
calloc.free(replaceEmailC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Free the mailmap and its associated memory.

View file

@ -25,8 +25,6 @@ Pointer<git_oid> mergeBase({
/// Analyzes the given branch(es) and determines the opportunities for merging them
/// into a reference.
///
/// Throws a [LibGit2Error] if error occured.
List<int> analysis({
required Pointer<git_repository> repoPointer,
required Pointer<git_reference> ourRefPointer,
@ -35,7 +33,7 @@ List<int> analysis({
}) {
final analysisOut = calloc<Int32>();
final preferenceOut = calloc<Int32>();
final error = libgit2.git_merge_analysis_for_ref(
libgit2.git_merge_analysis_for_ref(
analysisOut,
preferenceOut,
repoPointer,
@ -43,60 +41,35 @@ List<int> analysis({
theirHeadPointer,
theirHeadsLen,
);
var result = <int>[];
if (error < 0) {
calloc.free(analysisOut);
calloc.free(preferenceOut);
throw LibGit2Error(libgit2.git_error_last());
} else {
result.add(analysisOut.value);
result.add(preferenceOut.value);
calloc.free(analysisOut);
calloc.free(preferenceOut);
return result;
}
final result = [analysisOut.value, preferenceOut.value];
calloc.free(analysisOut);
calloc.free(preferenceOut);
return result;
}
/// Merges the given commit(s) into HEAD, writing the results into the working directory.
/// Any changes are staged for commit and any conflicts are written to the index. Callers
/// should inspect the repository's index after this completes, resolve any conflicts and
/// prepare a commit.
///
/// Throws a [LibGit2Error] if error occured.
void merge({
required Pointer<git_repository> repoPointer,
required Pointer<Pointer<git_annotated_commit>> theirHeadsPointer,
required int theirHeadsLen,
}) {
final mergeOpts = calloc<git_merge_options>();
final mergeError = libgit2.git_merge_options_init(
mergeOpts,
GIT_MERGE_OPTIONS_VERSION,
);
if (mergeError < 0) {
calloc.free(mergeOpts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_merge_options_init(mergeOpts, GIT_MERGE_OPTIONS_VERSION);
final checkoutOpts = calloc<git_checkout_options>();
final checkoutError = libgit2.git_checkout_options_init(
checkoutOpts,
GIT_CHECKOUT_OPTIONS_VERSION,
);
if (checkoutError < 0) {
calloc.free(mergeOpts);
calloc.free(checkoutOpts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_checkout_options_init(checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION);
checkoutOpts.ref.checkout_strategy =
git_checkout_strategy_t.GIT_CHECKOUT_SAFE |
git_checkout_strategy_t.GIT_CHECKOUT_RECREATE_MISSING;
final error = libgit2.git_merge(
libgit2.git_merge(
repoPointer,
theirHeadsPointer,
theirHeadsLen,
@ -106,10 +79,6 @@ void merge({
calloc.free(mergeOpts);
calloc.free(checkoutOpts);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Merge two files as they exist in the index, using the given common ancestor
@ -235,15 +204,7 @@ void cherryPick({
required Pointer<git_commit> commitPointer,
}) {
final opts = calloc<git_cherrypick_options>();
final optsError = libgit2.git_cherrypick_options_init(
opts,
GIT_CHERRYPICK_OPTIONS_VERSION,
);
if (optsError < 0) {
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_cherrypick_options_init(opts, GIT_CHERRYPICK_OPTIONS_VERSION);
opts.ref.checkout_opts.checkout_strategy =
git_checkout_strategy_t.GIT_CHECKOUT_SAFE;
@ -263,15 +224,7 @@ Pointer<git_merge_options> _initMergeOptions({
required int fileFlags,
}) {
final opts = calloc<git_merge_options>();
final error = libgit2.git_merge_options_init(
opts,
GIT_MERGE_OPTIONS_VERSION,
);
if (error < 0) {
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_merge_options_init(opts, GIT_MERGE_OPTIONS_VERSION);
opts.ref.file_favor = favor;
opts.ref.flags = mergeFlags;

View file

@ -28,18 +28,9 @@ List<Map<String, Pointer>> list(Pointer<git_repository> repo) {
nextError = libgit2.git_note_next(noteOid, annotatedOid, iterator.value);
if (nextError >= 0) {
final out = calloc<Pointer<git_note>>();
final error = libgit2.git_note_read(out, repo, notesRef, annotatedOid);
libgit2.git_note_read(out, repo, notesRef, annotatedOid);
calloc.free(noteOid);
if (error < 0) {
calloc.free(out);
calloc.free(annotatedOid);
calloc.free(iterator);
throw LibGit2Error(libgit2.git_error_last());
} else {
result.add({'note': out.value, 'annotatedOid': annotatedOid});
}
result.add({'note': out.value, 'annotatedOid': annotatedOid});
} else {
break;
}

View file

@ -10,18 +10,10 @@ import '../util.dart';
///
/// Before the ODB can be used for read/writing, a custom database backend must be
/// manually added.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_odb> create() {
final out = calloc<Pointer<git_odb>>();
final error = libgit2.git_odb_new(out);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
libgit2.git_odb_new(out);
return out.value;
}
/// Add an on-disk alternate to an existing Object DB.
@ -33,20 +25,13 @@ Pointer<git_odb> create() {
/// have been exhausted.
///
/// Writing is disabled on alternate backends.
///
/// Throws a [LibGit2Error] if error occured.
void addDiskAlternate({
required Pointer<git_odb> odbPointer,
required String path,
}) {
final pathC = path.toNativeUtf8().cast<Int8>();
final error = libgit2.git_odb_add_disk_alternate(odbPointer, pathC);
libgit2.git_odb_add_disk_alternate(odbPointer, pathC);
calloc.free(pathC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Determine if an object can be found in the object database by an abbreviated object ID.
@ -174,7 +159,7 @@ void objectFree(Pointer<git_odb_object> object) {
libgit2.git_odb_object_free(object);
}
/// Write raw data to into the object database.
/// Write raw data into the object database.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> write({
@ -196,54 +181,15 @@ Pointer<git_oid> write({
}
final buffer = data.toNativeUtf8().cast<Int8>();
final writeError = libgit2.git_odb_stream_write(
stream.value,
buffer,
data.length,
);
if (writeError < 0) {
calloc.free(buffer);
libgit2.git_odb_stream_free(stream.value);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_odb_stream_write(stream.value, buffer, data.length);
final out = calloc<git_oid>();
final finalizeError = libgit2.git_odb_stream_finalize_write(
out,
stream.value,
);
libgit2.git_odb_stream_finalize_write(out, stream.value);
calloc.free(buffer);
libgit2.git_odb_stream_free(stream.value);
if (finalizeError < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out;
}
}
/// Get the number of ODB backend objects.
int backendsCount(Pointer<git_odb> odb) => libgit2.git_odb_num_backends(odb);
/// Lookup an ODB backend object by index.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_odb_backend> getBackend({
required Pointer<git_odb> odbPointer,
required int position,
}) {
final out = calloc<Pointer<git_odb_backend>>();
final error = libgit2.git_odb_get_backend(out, odbPointer, position);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
return out;
}
/// Close an open object database.

View file

@ -1,83 +1,54 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import '../error.dart';
import 'libgit2_bindings.dart';
import '../util.dart';
/// Parse N characters of a hex formatted object id into a git_oid.
///
/// If N is odd, the last byte's high nibble will be read in and the low nibble set to zero.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> fromStrN(String hex) {
final out = calloc<git_oid>();
final str = hex.toNativeUtf8().cast<Int8>();
final error = libgit2.git_oid_fromstrn(out, str, hex.length);
libgit2.git_oid_fromstrn(out, str, hex.length);
calloc.free(str);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out;
}
return out;
}
/// Parse a hex formatted object id into a git_oid.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> fromSHA(String hex) {
final out = calloc<git_oid>();
final str = hex.toNativeUtf8().cast<Int8>();
final error = libgit2.git_oid_fromstr(out, str);
libgit2.git_oid_fromstr(out, str);
calloc.free(str);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out;
}
return out;
}
/// Copy an already raw oid into a git_oid structure.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> fromRaw(Array<Uint8> raw) {
final out = calloc<git_oid>();
var rawC = calloc<Uint8>(20);
for (var i = 0; i < 20; i++) {
rawC[i] = raw[i];
}
final error = libgit2.git_oid_fromraw(out, rawC);
libgit2.git_oid_fromraw(out, rawC);
calloc.free(rawC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out;
}
return out;
}
/// Format a git_oid into a hex string.
///
/// Throws a [LibGit2Error] if error occured.
String toSHA(Pointer<git_oid> id) {
final out = calloc<Int8>(40);
final error = libgit2.git_oid_fmt(out, id);
libgit2.git_oid_fmt(out, id);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
final result = out.cast<Utf8>().toDartString(length: 40);
calloc.free(out);
return result;
}
final result = out.cast<Utf8>().toDartString(length: 40);
calloc.free(out);
return result;
}
/// Compare two oid structures.
@ -91,16 +62,8 @@ int compare({
}
/// Copy an oid from one structure to another.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> copy(Pointer<git_oid> src) {
final out = calloc<git_oid>();
final error = libgit2.git_oid_cpy(out, src);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out;
}
libgit2.git_oid_cpy(out, src);
return out;
}

View file

@ -7,9 +7,7 @@ import '../util.dart';
/// Directly generate a patch from the difference between two buffers.
///
/// You can use the standard patch accessor functions to read the patch data, and
/// you must call `free()` on the patch when done.
///
/// Throws a [LibGit2Error] if error occured.
/// you must free the patch when done.
Map<String, Pointer?> fromBuffers({
String? oldBuffer,
String? oldAsPath,
@ -32,7 +30,7 @@ Map<String, Pointer?> fromBuffers({
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_buffers(
libgit2.git_patch_from_buffers(
out,
oldBufferC.cast(),
oldLen,
@ -47,29 +45,20 @@ Map<String, Pointer?> fromBuffers({
calloc.free(newAsPathC);
calloc.free(opts);
if (error < 0) {
calloc.free(out);
calloc.free(oldBufferC);
calloc.free(newBufferC);
throw LibGit2Error(libgit2.git_error_last());
} else {
// Returning map with pointers to patch and buffers because patch object does not
// have refenrece to underlying buffers or blobs. So if the buffer or blob is freed/removed
// the patch text becomes corrupted.
return {'patch': out.value, 'a': oldBufferC, 'b': newBufferC};
}
// Returning map with pointers to patch and buffers because patch object does not
// have refenrece to underlying buffers or blobs. So if the buffer or blob is freed/removed
// the patch text becomes corrupted.
return {'patch': out.value, 'a': oldBufferC, 'b': newBufferC};
}
/// Directly generate a patch from the difference between two blobs.
///
/// You can use the standard patch accessor functions to read the patch data, and you
/// must call `free()` on the patch when done.
///
/// Throws a [LibGit2Error] if error occured.
/// must free the patch when done.
Map<String, Pointer?> fromBlobs({
Pointer<git_blob>? oldBlobPointer,
required Pointer<git_blob> oldBlobPointer,
String? oldAsPath,
Pointer<git_blob>? newBlobPointer,
required Pointer<git_blob> newBlobPointer,
String? newAsPath,
required int flags,
required int contextLines,
@ -84,11 +73,11 @@ Map<String, Pointer?> fromBlobs({
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_blobs(
libgit2.git_patch_from_blobs(
out,
oldBlobPointer ?? nullptr,
oldBlobPointer,
oldAsPathC,
newBlobPointer ?? nullptr,
newBlobPointer,
newAsPathC,
opts,
);
@ -97,23 +86,16 @@ Map<String, Pointer?> fromBlobs({
calloc.free(newAsPathC);
calloc.free(opts);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
// Returning map with pointers to patch and blobs because patch object does not
// have reference to underlying blobs. So if the blob is freed/removed the patch
// text becomes corrupted.
return {'patch': out.value, 'a': oldBlobPointer, 'b': newBlobPointer};
}
// Returning map with pointers to patch and blobs because patch object does not
// have reference to underlying blobs. So if the blob is freed/removed the patch
// text becomes corrupted.
return {'patch': out.value, 'a': oldBlobPointer, 'b': newBlobPointer};
}
/// Directly generate a patch from the difference between a blob and a buffer.
///
/// You can use the standard patch accessor functions to read the patch data, and you must
/// call `free()` on the patch when done.
///
/// Throws a [LibGit2Error] if error occured.
/// free the patch when done.
Map<String, Pointer?> fromBlobAndBuffer({
Pointer<git_blob>? oldBlobPointer,
String? oldAsPath,
@ -134,7 +116,7 @@ Map<String, Pointer?> fromBlobAndBuffer({
interhunkLines: interhunkLines,
);
final error = libgit2.git_patch_from_blob_and_buffer(
libgit2.git_patch_from_blob_and_buffer(
out,
oldBlobPointer ?? nullptr,
oldAsPathC,
@ -148,16 +130,10 @@ Map<String, Pointer?> fromBlobAndBuffer({
calloc.free(bufferAsPathC);
calloc.free(opts);
if (error < 0) {
calloc.free(out);
calloc.free(bufferC);
throw LibGit2Error(libgit2.git_error_last());
} else {
// Returning map with pointers to patch and buffers because patch object does not
// have reference to underlying buffers or blobs. So if the buffer or blob is freed/removed
// the patch text becomes corrupted.
return {'patch': out.value, 'a': oldBlobPointer, 'b': bufferC};
}
// Returning map with pointers to patch and buffers because patch object does not
// have reference to underlying buffers or blobs. So if the buffer or blob is freed/removed
// the patch text becomes corrupted.
return {'patch': out.value, 'a': oldBlobPointer, 'b': bufferC};
}
/// Return a patch for an entry in the diff list.
@ -191,55 +167,31 @@ int numHunks(Pointer<git_patch> patch) => libgit2.git_patch_num_hunks(patch);
/// Get the information about a hunk in a patch.
///
/// Given a patch and a hunk index into the patch, this returns detailed information about that hunk.
///
/// Throws a [LibGit2Error] if error occured.
/// Given a patch and a hunk index into the patch, this returns detailed information
/// about that hunk.
Map<String, Object> hunk({
required Pointer<git_patch> patchPointer,
required int hunkIndex,
}) {
final out = calloc<Pointer<git_diff_hunk>>();
final linesInHunk = calloc<Int64>();
final error = libgit2.git_patch_get_hunk(
out,
linesInHunk.cast(),
patchPointer,
hunkIndex,
);
libgit2.git_patch_get_hunk(out, linesInHunk.cast(), patchPointer, hunkIndex);
if (error < 0) {
calloc.free(out);
calloc.free(linesInHunk);
throw LibGit2Error(libgit2.git_error_last());
} else {
final linesN = linesInHunk.value;
calloc.free(linesInHunk);
return {'hunk': out.value, 'linesN': linesN};
}
final linesN = linesInHunk.value;
calloc.free(linesInHunk);
return {'hunk': out.value, 'linesN': linesN};
}
/// Get data about a line in a hunk of a patch.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_diff_line> lines({
required Pointer<git_patch> patchPointer,
required int hunkIndex,
required int lineOfHunk,
}) {
final out = calloc<Pointer<git_diff_line>>();
final error = libgit2.git_patch_get_line_in_hunk(
out,
patchPointer,
hunkIndex,
lineOfHunk,
);
libgit2.git_patch_get_line_in_hunk(out, patchPointer, hunkIndex, lineOfHunk);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
return out.value;
}
/// Get the content of a patch as a single diff text.
@ -294,15 +246,7 @@ Pointer<git_diff_options> _diffOptionsInit({
required int interhunkLines,
}) {
final opts = calloc<git_diff_options>();
final optsError = libgit2.git_diff_options_init(
opts,
GIT_DIFF_OPTIONS_VERSION,
);
if (optsError < 0) {
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_diff_options_init(opts, GIT_DIFF_OPTIONS_VERSION);
opts.ref.flags = flags;
opts.ref.context_lines = contextLines;

View file

@ -25,16 +25,7 @@ Pointer<git_rebase> init({
final out = calloc<Pointer<git_rebase>>();
final opts = calloc<git_rebase_options>();
final optsError = libgit2.git_rebase_options_init(
opts,
GIT_REBASE_OPTIONS_VERSION,
);
if (optsError < 0) {
calloc.free(out);
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_rebase_options_init(opts, GIT_REBASE_OPTIONS_VERSION);
final error = libgit2.git_rebase_init(
out,
@ -110,27 +101,12 @@ void commit({
}
/// Finishes a rebase that is currently in progress once all patches have been applied.
///
/// Throws a [LibGit2Error] if error occured.
void finish(Pointer<git_rebase> rebase) {
final error = libgit2.git_rebase_finish(rebase, nullptr);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void finish(Pointer<git_rebase> rebase) =>
libgit2.git_rebase_finish(rebase, nullptr);
/// Aborts a rebase that is currently in progress, resetting the repository and working
/// directory to their state before rebase began.
///
/// Throws a [LibGit2Error] if error occured.
void abort(Pointer<git_rebase> rebase) {
final error = libgit2.git_rebase_abort(rebase);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void abort(Pointer<git_rebase> rebase) => libgit2.git_rebase_abort(rebase);
/// Free memory allocated for rebase object.
void free(Pointer<git_rebase> rebase) => libgit2.git_rebase_free(rebase);

View file

@ -1,20 +1,11 @@
import 'dart:ffi';
import '../error.dart';
import 'libgit2_bindings.dart';
import '../util.dart';
/// Suggests that the given refdb compress or optimize its references.
/// This mechanism is implementation specific. For on-disk reference databases,
/// for example, this may pack all loose references.
///
/// Throws a [LibGit2Error] if error occured.
void compress(Pointer<git_refdb> refdb) {
final error = libgit2.git_refdb_compress(refdb);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void compress(Pointer<git_refdb> refdb) => libgit2.git_refdb_compress(refdb);
/// Close an open reference database to release memory.
void free(Pointer<git_refdb> refdb) => libgit2.git_refdb_free(refdb);

View file

@ -13,17 +13,8 @@ int referenceType(Pointer<git_reference> ref) =>
/// Get the OID pointed to by a direct reference.
///
/// Only available if the reference is direct (i.e. an object id reference, not a symbolic one).
///
/// Throws an exception if error occured.
Pointer<git_oid> target(Pointer<git_reference> ref) {
final result = libgit2.git_reference_target(ref);
if (result == nullptr) {
throw Exception('Oid for reference isn\'t available');
} else {
return result;
}
}
Pointer<git_oid> target(Pointer<git_reference> ref) =>
libgit2.git_reference_target(ref);
/// Resolve a symbolic reference to a direct reference.
///
@ -73,30 +64,6 @@ Pointer<git_reference> lookup({
}
}
/// Lookup a reference by DWIMing its short name.
///
/// Apply the git precendence rules to the given shorthand to determine which reference
/// the user is referring to.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reference> lookupDWIM({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reference>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_dwim(out, repoPointer, nameC);
calloc.free(nameC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Get the full name of a reference.
String name(Pointer<git_reference> ref) {
return libgit2.git_reference_name(ref).cast<Utf8>().toDartString();
@ -175,22 +142,16 @@ List<String> list(Pointer<git_repository> repo) {
}
/// Check if a reflog exists for the specified reference.
///
/// Throws a [LibGit2Error] if error occured.
bool hasLog({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final refname = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reference_has_log(repoPointer, refname);
final result = libgit2.git_reference_has_log(repoPointer, refname);
calloc.free(refname);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else {
return error == 1 ? true : false;
}
return result == 1 ? true : false;
}
/// Check if a reference is a local branch.
@ -329,15 +290,7 @@ Pointer<git_reference> createSymbolic({
///
/// This method works for both direct and symbolic references.
/// The reference will be immediately removed on disk but the memory will not be freed.
///
/// Throws a [LibGit2Error] if the reference has changed from the time it was looked up.
void delete(Pointer<git_reference> ref) {
final error = libgit2.git_reference_delete(ref);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void delete(Pointer<git_reference> ref) => libgit2.git_reference_delete(ref);
/// Get the repository where a reference resides.
Pointer<git_repository> owner(Pointer<git_reference> ref) {
@ -444,23 +397,5 @@ Pointer<git_object> peel({
}
}
/// Ensure the reference name is well-formed.
///
/// Valid reference names must follow one of two patterns:
///
/// Top-level names must contain only capital letters and underscores,
/// and must begin and end with a letter. (e.g. "HEAD", "ORIG_HEAD").
/// Names prefixed with "refs/" can be almost anything. You must avoid
/// the characters '~', '^', ':', '\', '?', '[', and '*', and the sequences ".."
/// and "@{" which have special meaning to revparse.
bool isValidName(String name) {
final refname = name.toNativeUtf8().cast<Int8>();
final result = libgit2.git_reference_is_valid_name(refname);
calloc.free(refname);
return result == 1 ? true : false;
}
/// Free the given reference.
void free(Pointer<git_reference> ref) => libgit2.git_reference_free(ref);

View file

@ -1,6 +1,5 @@
import 'dart:ffi';
import 'package:ffi/ffi.dart';
import '../error.dart';
import 'libgit2_bindings.dart';
import '../util.dart';
@ -10,24 +9,17 @@ import '../util.dart';
/// object will be returned.
///
/// The reflog must be freed manually.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_reflog> read({
required Pointer<git_repository> repoPointer,
required String name,
}) {
final out = calloc<Pointer<git_reflog>>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_reflog_read(out, repoPointer, nameC);
libgit2.git_reflog_read(out, repoPointer, nameC);
calloc.free(nameC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
return out.value;
}
/// Get the number of log entries in a reflog.

View file

@ -12,19 +12,16 @@ import 'remote_callbacks.dart';
/// Throws a [LibGit2Error] if error occured.
List<String> list(Pointer<git_repository> repo) {
final out = calloc<git_strarray>();
final error = libgit2.git_remote_list(out, repo);
libgit2.git_remote_list(out, repo);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
var result = <String>[];
for (var i = 0; i < out.ref.count; i++) {
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
}
calloc.free(out);
return result;
var result = <String>[];
for (var i = 0; i < out.ref.count; i++) {
result.add(out.ref.strings[i].cast<Utf8>().toDartString());
}
calloc.free(out);
return result;
}
/// Get the information for a particular remote.
@ -210,11 +207,6 @@ void setPushUrl({
}
}
/// Get the remote's repository.
Pointer<git_repository> owner(Pointer<git_remote> remote) {
return libgit2.git_remote_owner(remote);
}
/// Get the remote's name.
String name(Pointer<git_remote> remote) {
final result = libgit2.git_remote_name(remote);
@ -332,7 +324,7 @@ void connect({
String? proxyOption,
}) {
final callbacksOptions = calloc<git_remote_callbacks>();
final callbacksError = libgit2.git_remote_init_callbacks(
libgit2.git_remote_init_callbacks(
callbacksOptions,
GIT_REMOTE_CALLBACKS_VERSION,
);
@ -342,10 +334,6 @@ void connect({
callbacks: callbacks,
);
if (callbacksError < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
final proxyOptions = _proxyOptionsInit(proxyOption);
final error = libgit2.git_remote_connect(
@ -377,42 +365,32 @@ void connect({
List<Map<String, Object?>> lsRemotes(Pointer<git_remote> remote) {
final out = calloc<Pointer<Pointer<git_remote_head>>>();
final size = calloc<Uint64>();
final error = libgit2.git_remote_ls(out, size, remote);
libgit2.git_remote_ls(out, size, remote);
if (error < 0) {
calloc.free(out);
calloc.free(size);
throw LibGit2Error(libgit2.git_error_last());
} else {
var result = <Map<String, Object?>>[];
var result = <Map<String, Object?>>[];
for (var i = 0; i < size.value; i++) {
var remote = <String, Object?>{};
Oid? loid;
for (var i = 0; i < size.value; i++) {
var remote = <String, Object?>{};
final bool local = out[0][i].ref.local == 1 ? true : false;
if (local) {
loid = Oid.fromRaw(out[0][i].ref.loid);
}
final local = out[0][i].ref.local == 1 ? true : false;
remote['local'] = local;
remote['loid'] = loid;
remote['name'] = out[0][i].ref.name == nullptr
? ''
: out[0][i].ref.name.cast<Utf8>().toDartString();
remote['symref'] = out[0][i].ref.symref_target == nullptr
? ''
: out[0][i].ref.symref_target.cast<Utf8>().toDartString();
remote['oid'] = Oid.fromRaw(out[0][i].ref.oid);
remote['local'] = local;
remote['loid'] = local ? Oid.fromRaw(out[0][i].ref.loid) : null;
remote['name'] = out[0][i].ref.name == nullptr
? ''
: out[0][i].ref.name.cast<Utf8>().toDartString();
remote['symref'] = out[0][i].ref.symref_target == nullptr
? ''
: out[0][i].ref.symref_target.cast<Utf8>().toDartString();
remote['oid'] = Oid.fromRaw(out[0][i].ref.oid);
result.add(remote);
}
calloc.free(out);
calloc.free(size);
return result;
result.add(remote);
}
calloc.free(out);
calloc.free(size);
return result;
}
/// Download new data and update tips.
@ -445,22 +423,7 @@ void fetch({
final proxyOptions = _proxyOptionsInit(proxyOption);
final opts = calloc<git_fetch_options>();
final optsError = libgit2.git_fetch_options_init(
opts,
GIT_FETCH_OPTIONS_VERSION,
);
if (optsError < 0) {
for (final p in refspecsPointers) {
calloc.free(p);
}
calloc.free(refspecsC);
calloc.free(strArray);
calloc.free(proxyOptions);
calloc.free(reflogMessageC);
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_fetch_options_init(opts, GIT_FETCH_OPTIONS_VERSION);
RemoteCallbacks.plug(
callbacksOptions: opts.ref.callbacks,
@ -515,19 +478,7 @@ void push({
final proxyOptions = _proxyOptionsInit(proxyOption);
final opts = calloc<git_push_options>();
final optsError =
libgit2.git_push_options_init(opts, GIT_PUSH_OPTIONS_VERSION);
if (optsError < 0) {
for (final p in refspecsPointers) {
calloc.free(p);
}
calloc.free(strArray);
calloc.free(refspecsC);
calloc.free(proxyOptions);
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_push_options_init(opts, GIT_PUSH_OPTIONS_VERSION);
RemoteCallbacks.plug(
callbacksOptions: opts.ref.callbacks,
@ -556,15 +507,8 @@ Pointer<git_indexer_progress> stats(Pointer<git_remote> remote) =>
libgit2.git_remote_stats(remote);
/// Close the connection to the remote.
///
/// Throws a [LibGit2Error] if error occured.
void disconnect(Pointer<git_remote> remote) {
final error = libgit2.git_remote_disconnect(remote);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void disconnect(Pointer<git_remote> remote) =>
libgit2.git_remote_disconnect(remote);
/// Prune tracking refs that are no longer present on remote.
///
@ -574,16 +518,11 @@ void prune({
required Callbacks callbacks,
}) {
final callbacksOptions = calloc<git_remote_callbacks>();
final callbacksError = libgit2.git_remote_init_callbacks(
libgit2.git_remote_init_callbacks(
callbacksOptions,
GIT_REMOTE_CALLBACKS_VERSION,
);
if (callbacksError < 0) {
calloc.free(callbacksOptions);
throw LibGit2Error(libgit2.git_error_last());
}
RemoteCallbacks.plug(
callbacksOptions: callbacksOptions.ref,
callbacks: callbacks,
@ -608,13 +547,7 @@ void free(Pointer<git_remote> remote) => libgit2.git_remote_free(remote);
/// Initializes git_proxy_options structure.
Pointer<git_proxy_options> _proxyOptionsInit(String? proxyOption) {
final proxyOptions = calloc<git_proxy_options>();
final proxyOptionsError =
libgit2.git_proxy_options_init(proxyOptions, GIT_PROXY_OPTIONS_VERSION);
if (proxyOptionsError < 0) {
calloc.free(proxyOptions);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_proxy_options_init(proxyOptions, GIT_PROXY_OPTIONS_VERSION);
if (proxyOption == null) {
proxyOptions.ref.type = git_proxy_t.GIT_PROXY_NONE;

View file

@ -28,33 +28,11 @@ Pointer<git_repository> open(String path) {
}
}
/// Attempt to open an already-existing bare repository at [bare_path].
///
/// The [bare_path] can point to only a bare repository.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_repository> openBare(String barePath) {
final out = calloc<Pointer<git_repository>>();
final barePathC = barePath.toNativeUtf8().cast<Int8>();
final error = libgit2.git_repository_open_bare(out, barePathC);
calloc.free(barePathC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Look for a git repository and return its path. The lookup start from [startPath]
/// and walk across parent directories if nothing has been found. The lookup ends when
/// the first repository is found, or when reaching a directory referenced in [ceilingDirs].
///
/// The method will automatically detect if the repository is bare (if there is a repository).
///
/// Throws a [LibGit2Error] if error occured.
String discover({
required String startPath,
String? ceilingDirs,
@ -63,27 +41,14 @@ String discover({
final startPathC = startPath.toNativeUtf8().cast<Int8>();
final ceilingDirsC = ceilingDirs?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_repository_discover(
out,
startPathC,
0,
ceilingDirsC,
);
libgit2.git_repository_discover(out, startPathC, 0, ceilingDirsC);
calloc.free(startPathC);
calloc.free(ceilingDirsC);
if (error == git_error_code.GIT_ENOTFOUND) {
calloc.free(out);
return '';
} else if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
final result = out.ref.ptr.cast<Utf8>().toDartString();
calloc.free(out);
return result;
}
final result = out.ref.ptr.cast<Utf8>().toDartString();
calloc.free(out);
return result;
}
/// Creates a new Git repository in the given folder.
@ -107,23 +72,11 @@ Pointer<git_repository> init({
final initialHeadC = initialHead?.toNativeUtf8().cast<Int8>() ?? nullptr;
final originUrlC = originUrl?.toNativeUtf8().cast<Int8>() ?? nullptr;
final opts = calloc<git_repository_init_options>();
final optsError = libgit2.git_repository_init_options_init(
libgit2.git_repository_init_options_init(
opts,
GIT_REPOSITORY_INIT_OPTIONS_VERSION,
);
if (optsError < 0) {
calloc.free(out);
calloc.free(pathC);
calloc.free(workdirPathC);
calloc.free(descriptionC);
calloc.free(templatePathC);
calloc.free(initialHeadC);
calloc.free(originUrlC);
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
opts.ref.flags = flags;
opts.ref.mode = mode;
opts.ref.workdir_path = workdirPathC;
@ -169,31 +122,10 @@ Pointer<git_repository> clone({
checkoutBranch?.toNativeUtf8().cast<Int8>() ?? nullptr;
final cloneOptions = calloc<git_clone_options>();
final cloneOptionsError =
libgit2.git_clone_options_init(cloneOptions, GIT_CLONE_OPTIONS_VERSION);
if (cloneOptionsError < 0) {
calloc.free(out);
calloc.free(urlC);
calloc.free(localPathC);
calloc.free(checkoutBranchC);
calloc.free(cloneOptions);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_clone_options_init(cloneOptions, GIT_CLONE_OPTIONS_VERSION);
final fetchOptions = calloc<git_fetch_options>();
final fetchOptionsError =
libgit2.git_fetch_options_init(fetchOptions, GIT_FETCH_OPTIONS_VERSION);
if (fetchOptionsError < 0) {
calloc.free(out);
calloc.free(urlC);
calloc.free(localPathC);
calloc.free(checkoutBranchC);
calloc.free(cloneOptions);
calloc.free(fetchOptions);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_fetch_options_init(fetchOptions, GIT_FETCH_OPTIONS_VERSION);
RemoteCallbacks.plug(
callbacksOptions: fetchOptions.ref.callbacks,
@ -271,20 +203,13 @@ String getNamespace(Pointer<git_repository> repo) {
///
/// The [namespace] should not include the refs folder, e.g. to namespace all references
/// under refs/namespaces/foo/, use foo as the namespace.
///
/// Throws a [LibGit2Error] if error occured.
void setNamespace({
required Pointer<git_repository> repoPointer,
String? namespace,
}) {
final nmspace = namespace?.toNativeUtf8().cast<Int8>() ?? nullptr;
final error = libgit2.git_repository_set_namespace(repoPointer, nmspace);
libgit2.git_repository_set_namespace(repoPointer, nmspace);
calloc.free(nmspace);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Check if a repository is bare or not.
@ -401,18 +326,10 @@ Map<String, String> identity(Pointer<git_repository> repo) {
/// will be returned, including global and system configurations (if they are available).
///
/// The configuration file must be freed once it's no longer being used by the user.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_config> config(Pointer<git_repository> repo) {
final out = calloc<Pointer<git_config>>();
final error = libgit2.git_repository_config(out, repo);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
libgit2.git_repository_config(out, repo);
return out.value;
}
/// Get a snapshot of the repository's configuration.
@ -421,18 +338,10 @@ Pointer<git_config> config(Pointer<git_repository> repo) {
/// The contents of this snapshot will not change, even if the underlying config files are modified.
///
/// The configuration file must be freed once it's no longer being used by the user.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
final out = calloc<Pointer<git_config>>();
final error = libgit2.git_repository_config_snapshot(out, repo);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
libgit2.git_repository_config_snapshot(out, repo);
return out.value;
}
/// Get the Index file for this repository.
@ -441,18 +350,10 @@ Pointer<git_config> configSnapshot(Pointer<git_repository> repo) {
/// will be returned (the one located in `.git/index`).
///
/// The index must be freed once it's no longer being used.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_index> index(Pointer<git_repository> repo) {
final out = calloc<Pointer<git_index>>();
final error = libgit2.git_repository_index(out, repo);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
libgit2.git_repository_index(out, repo);
return out.value;
}
/// Determine if the repository was a shallow clone.
@ -585,27 +486,6 @@ void setHeadDetached({
}
}
/// Make the repository HEAD directly point to the commit.
///
/// This behaves like [setHeadDetached] but takes an annotated commit,
/// which lets you specify which extended sha syntax string was specified
/// by a user, allowing for more exact reflog messages.
///
/// See the documentation for [setHeadDetached].
void setHeadDetachedFromAnnotated({
required Pointer<git_repository> repoPointer,
required Pointer<git_annotated_commit> commitishPointer,
}) {
final error = libgit2.git_repository_set_head_detached_from_annotated(
repoPointer,
commitishPointer,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Set the path to the working directory for this repository.
///
/// The working directory doesn't need to be the same one that contains the
@ -665,24 +545,5 @@ String workdir(Pointer<git_repository> repo) {
}
}
/// Create a "fake" repository to wrap an object database
///
/// Create a repository object to wrap an object database to be used with the API
/// when all you have is an object database. This doesn't have any paths associated
/// with it, so use with care.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_repository> wrapODB(Pointer<git_odb> odb) {
final out = calloc<Pointer<git_repository>>();
final error = libgit2.git_repository_wrap_odb(out, odb);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
}
/// Free a previously allocated repository.
void free(Pointer<git_repository> repo) => libgit2.git_repository_free(repo);

View file

@ -1,5 +1,4 @@
import 'dart:ffi';
import '../error.dart';
import 'libgit2_bindings.dart';
import '../util.dart';
@ -13,22 +12,11 @@ import '../util.dart';
///
/// HARD reset will trigger a MIXED reset and the working directory will be replaced
/// with the content of the index. (Untracked and ignored files will be left alone, however.)
///
/// Throws a [LibGit2Error] if error occured.
void reset({
required Pointer<git_repository> repoPointer,
required Pointer<git_object> targetPointer,
required int resetType,
required Pointer<git_checkout_options> checkoutOptsPointer,
}) {
final error = libgit2.git_reset(
repoPointer,
targetPointer,
resetType,
checkoutOptsPointer,
);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_reset(repoPointer, targetPointer, resetType, checkoutOptsPointer);
}

View file

@ -32,17 +32,11 @@ Pointer<git_revwalk> create(Pointer<git_repository> repo) {
/// Change the sorting mode when iterating through the repository's contents.
///
/// Changing the sorting mode resets the walker.
///
/// Throws a [LibGit2Error] if error occured.
void sorting({
required Pointer<git_revwalk> walkerPointer,
required int sortMode,
}) {
final error = libgit2.git_revwalk_sorting(walkerPointer, sortMode);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_revwalk_sorting(walkerPointer, sortMode);
}
/// Add a new root for the traversal.
@ -130,14 +124,8 @@ void reset(Pointer<git_revwalk> walker) => libgit2.git_revwalk_reset(walker);
/// Simplify the history by first-parent.
///
/// No parents other than the first for each commit will be enqueued.
///
/// Throws a [LibGit2Error] if error occured.
void simplifyFirstParent(Pointer<git_revwalk> walker) {
final error = libgit2.git_revwalk_simplify_first_parent(walker);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_revwalk_simplify_first_parent(walker);
}
/// Return the repository on which this walker is operating.

View file

@ -56,18 +56,10 @@ Pointer<git_signature> now({required String name, required String email}) {
///
/// This looks up the user.name and user.email from the configuration and uses the
/// current time as the timestamp, and creates a new signature based on that information.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_signature> defaultSignature(Pointer<git_repository> repo) {
final out = calloc<Pointer<git_signature>>();
final error = libgit2.git_signature_default(out, repo);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out.value;
}
libgit2.git_signature_default(out, repo);
return out.value;
}
/// Free an existing signature.

View file

@ -48,16 +48,11 @@ void apply({
List<String>? paths,
}) {
final options = calloc<git_stash_apply_options>();
final optionsError = libgit2.git_stash_apply_options_init(
libgit2.git_stash_apply_options_init(
options,
GIT_STASH_APPLY_OPTIONS_VERSION,
);
if (optionsError < 0) {
calloc.free(options);
throw LibGit2Error(libgit2.git_error_last());
}
final checkoutOptions = checkout_bindings.initOptions(
strategy: strategy,
directory: directory,
@ -88,7 +83,11 @@ void apply({
///
/// Throws a [LibGit2Error] if error occured.
void drop({required Pointer<git_repository> repoPointer, required int index}) {
libgit2.git_stash_drop(repoPointer, index);
final error = libgit2.git_stash_drop(repoPointer, index);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Apply a single stashed state from the stash list and remove it from the list if successful.
@ -103,16 +102,11 @@ void pop({
List<String>? paths,
}) {
final options = calloc<git_stash_apply_options>();
final optionsError = libgit2.git_stash_apply_options_init(
libgit2.git_stash_apply_options_init(
options,
GIT_STASH_APPLY_OPTIONS_VERSION,
);
if (optionsError < 0) {
calloc.free(options);
throw LibGit2Error(libgit2.git_error_last());
}
final checkoutOptions = checkout_bindings.initOptions(
strategy: strategy,
directory: directory,

View file

@ -31,19 +31,11 @@ int listEntryCount(Pointer<git_status_list> statuslist) {
/// Get a pointer to one of the entries in the status list.
///
/// The entry is not modifiable and should not be freed.
///
/// Throws [RangeError] if position is out of bounds
Pointer<git_status_entry> getByIndex({
required Pointer<git_status_list> statuslistPointer,
required int index,
}) {
final result = libgit2.git_status_byindex(statuslistPointer, index);
if (result == nullptr) {
throw RangeError('Out of bounds');
} else {
return result;
}
return libgit2.git_status_byindex(statuslistPointer, index);
}
/// Get file status for a single file.

View file

@ -22,24 +22,17 @@ int _listCb(
}
/// Returns a list with all tracked submodules paths of a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> list(Pointer<git_repository> repo) {
const except = -1;
final callback = Pointer.fromFunction<
Int32 Function(Pointer<git_submodule>, Pointer<Int8>, Pointer<Void>)>(
_listCb, except);
final error = libgit2.git_submodule_foreach(repo, callback, nullptr);
libgit2.git_submodule_foreach(repo, callback, nullptr);
if (error < 0) {
_pathsList.clear();
throw LibGit2Error(libgit2.git_error_last());
} else {
final result = _pathsList.toList(growable: false);
_pathsList.clear();
return result;
}
final result = _pathsList.toList(growable: false);
_pathsList.clear();
return result;
}
/// Lookup submodule information by name or path.
@ -76,18 +69,12 @@ Pointer<git_submodule> lookup({
///
/// By default, existing entries will not be overwritten, but setting [overwrite]
/// to true forces them to be updated.
///
/// Throws a [LibGit2Error] if error occured.
void init({
required Pointer<git_submodule> submodulePointer,
bool overwrite = false,
}) {
final overwriteC = overwrite ? 1 : 0;
final error = libgit2.git_submodule_init(submodulePointer, overwriteC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_submodule_init(submodulePointer, overwriteC);
}
/// Update a submodule. This will clone a missing submodule and checkout the
@ -108,16 +95,11 @@ void update({
}) {
final initC = init ? 1 : 0;
final options = calloc<git_submodule_update_options>();
final optionsError = libgit2.git_submodule_update_options_init(
libgit2.git_submodule_update_options_init(
options,
GIT_SUBMODULE_UPDATE_OPTIONS_VERSION,
);
if (optionsError < 0) {
calloc.free(options);
throw LibGit2Error(libgit2.git_error_last());
}
RemoteCallbacks.plug(
callbacksOptions: options.ref.fetch_opts.callbacks,
callbacks: callbacks,
@ -199,17 +181,11 @@ void clone({
}) {
final out = calloc<Pointer<git_repository>>();
final options = calloc<git_submodule_update_options>();
final optionsError = libgit2.git_submodule_update_options_init(
libgit2.git_submodule_update_options_init(
options,
GIT_SUBMODULE_UPDATE_OPTIONS_VERSION,
);
if (optionsError < 0) {
calloc.free(out);
calloc.free(options);
throw LibGit2Error(libgit2.git_error_last());
}
RemoteCallbacks.plug(
callbacksOptions: options.ref.fetch_opts.callbacks,
callbacks: callbacks,
@ -232,22 +208,14 @@ void clone({
/// the clone of the submodule. This adds the `.gitmodules` file and the newly
/// cloned submodule to the index to be ready to be committed (but doesn't actually
/// do the commit).
///
/// Throws a [LibGit2Error] if error occured.
void addFinalize(Pointer<git_submodule> submodule) {
final error = libgit2.git_submodule_add_finalize(submodule);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_submodule_add_finalize(submodule);
}
/// Get the status for a submodule.
///
/// This looks at a submodule and tries to determine the status. How deeply it examines
/// the working directory to do this will depend on the [ignore] value.
///
/// Throws a [LibGit2Error] if error occured.
int status({
required Pointer<git_repository> repoPointer,
required String name,
@ -255,18 +223,13 @@ int status({
}) {
final out = calloc<Uint32>();
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_submodule_status(out, repoPointer, nameC, ignore);
libgit2.git_submodule_status(out, repoPointer, nameC, ignore);
calloc.free(nameC);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
final result = out.value;
calloc.free(out);
return result;
}
final result = out.value;
calloc.free(out);
return result;
}
/// Copy submodule remote info into submodule repo.
@ -275,15 +238,8 @@ int status({
/// config, acting like `git submodule sync`. This is useful if you have altered the URL
/// for the submodule (or it has been altered by a fetch of upstream changes) and you
/// need to update your local repo.
///
/// Throws a [LibGit2Error] if error occured.
void sync(Pointer<git_submodule> submodule) {
final error = libgit2.git_submodule_sync(submodule);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void sync(Pointer<git_submodule> submodule) =>
libgit2.git_submodule_sync(submodule);
/// Reread submodule info from config, index, and HEAD.
///
@ -296,11 +252,7 @@ void reload({
bool force = false,
}) {
final forceC = force ? 1 : 0;
final error = libgit2.git_submodule_reload(submodulePointer, forceC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_submodule_reload(submodulePointer, forceC);
}
/// Get the name of submodule.
@ -325,8 +277,6 @@ String url(Pointer<git_submodule> submodule) {
///
/// After calling this, you may wish to call [sync] to write the changes to
/// the checked out submodule repository.
///
/// Throws a [LibGit2Error] if error occured.
void setUrl({
required Pointer<git_repository> repoPointer,
required String name,
@ -335,14 +285,10 @@ void setUrl({
final nameC = name.toNativeUtf8().cast<Int8>();
final urlC = url.toNativeUtf8().cast<Int8>();
final error = libgit2.git_submodule_set_url(repoPointer, nameC, urlC);
libgit2.git_submodule_set_url(repoPointer, nameC, urlC);
calloc.free(nameC);
calloc.free(urlC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Get the branch for the submodule.
@ -355,8 +301,6 @@ String branch(Pointer<git_submodule> submodule) {
///
/// After calling this, you may wish to call [sync] to write the changes to
/// the checked out submodule repository.
///
/// Throws a [LibGit2Error] if error occured.
void setBranch({
required Pointer<git_repository> repoPointer,
required String name,
@ -365,14 +309,10 @@ void setBranch({
final nameC = name.toNativeUtf8().cast<Int8>();
final branchC = branch.toNativeUtf8().cast<Int8>();
final error = libgit2.git_submodule_set_branch(repoPointer, nameC, branchC);
libgit2.git_submodule_set_branch(repoPointer, nameC, branchC);
calloc.free(nameC);
calloc.free(branchC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Get the OID for the submodule in the current HEAD tree.
@ -412,21 +352,14 @@ int ignore(Pointer<git_submodule> submodule) {
/// Set the ignore rule for the submodule in the configuration.
///
/// This does not affect any currently-loaded instances.
///
/// Throws a [LibGit2Error] if error occured.
void setIgnore({
required Pointer<git_repository> repoPointer,
required String name,
required int ignore,
}) {
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_submodule_set_ignore(repoPointer, nameC, ignore);
libgit2.git_submodule_set_ignore(repoPointer, nameC, ignore);
calloc.free(nameC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Get the update rule that will be used for the submodule.
@ -439,21 +372,14 @@ int updateRule(Pointer<git_submodule> submodule) {
/// Set the update rule for the submodule in the configuration.
///
/// This setting won't affect any existing instances.
///
/// Throws a [LibGit2Error] if error occured.
void setUpdateRule({
required Pointer<git_repository> repoPointer,
required String name,
required int update,
}) {
final nameC = name.toNativeUtf8().cast<Int8>();
final error = libgit2.git_submodule_set_update(repoPointer, nameC, update);
libgit2.git_submodule_set_update(repoPointer, nameC, update);
calloc.free(nameC);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
/// Get the containing repository for a submodule.

View file

@ -142,10 +142,5 @@ void delete({
}
}
/// Get the repository that contains the tag.
Pointer<git_repository> owner(Pointer<git_tag> tag) {
return libgit2.git_tag_owner(tag);
}
/// Close an open tag to release memory.
void free(Pointer<git_tag> tag) => libgit2.git_tag_free(tag);

View file

@ -109,16 +109,6 @@ String entryName(Pointer<git_tree_entry> entry) =>
int entryFilemode(Pointer<git_tree_entry> entry) =>
libgit2.git_tree_entry_filemode(entry);
/// Compare two tree entries.
///
/// Returns <0 if e1 is before e2, 0 if e1 == e2, >0 if e1 is after e2.
int compare({
required Pointer<git_tree_entry> aPointer,
required Pointer<git_tree_entry> bPointer,
}) {
return libgit2.git_tree_entry_cmp(aPointer, bPointer);
}
/// Free a user-owned tree entry.
///
/// IMPORTANT: This function is only needed for tree entries owned by the user,

View file

@ -32,30 +32,14 @@ Pointer<git_treebuilder> create({
}
/// Write the contents of the tree builder as a tree object.
///
/// Throws a [LibGit2Error] if error occured.
Pointer<git_oid> write(Pointer<git_treebuilder> bld) {
final out = calloc<git_oid>();
final error = libgit2.git_treebuilder_write(out, bld);
if (error < 0) {
calloc.free(out);
throw LibGit2Error(libgit2.git_error_last());
} else {
return out;
}
libgit2.git_treebuilder_write(out, bld);
return out;
}
/// Clear all the entires in the builder.
///
/// Throws a [LibGit2Error] if error occured.
void clear(Pointer<git_treebuilder> bld) {
final error = libgit2.git_treebuilder_clear(bld);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
}
void clear(Pointer<git_treebuilder> bld) => libgit2.git_treebuilder_clear(bld);
/// Get the number of entries listed in a treebuilder.
int entryCount(Pointer<git_treebuilder> bld) =>

View file

@ -22,18 +22,7 @@ Pointer<git_worktree> create({
final pathC = path.toNativeUtf8().cast<Int8>();
final opts = calloc<git_worktree_add_options>();
final optsError = libgit2.git_worktree_add_options_init(
opts,
GIT_WORKTREE_ADD_OPTIONS_VERSION,
);
if (optsError < 0) {
calloc.free(out);
calloc.free(nameC);
calloc.free(pathC);
calloc.free(opts);
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_worktree_add_options_init(opts, GIT_WORKTREE_ADD_OPTIONS_VERSION);
opts.ref.ref = nullptr;
if (refPointer != null) {
@ -84,29 +73,19 @@ Pointer<git_worktree> lookup({
/// Throws a [LibGit2Error] if error occured.
bool isPrunable(Pointer<git_worktree> wt) {
final opts = calloc<git_worktree_prune_options>();
final optsError = libgit2.git_worktree_prune_options_init(
libgit2.git_worktree_prune_options_init(
opts,
GIT_WORKTREE_PRUNE_OPTIONS_VERSION,
);
if (optsError < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
return libgit2.git_worktree_is_prunable(wt, opts) > 0 ? true : false;
}
/// Prune working tree.
///
/// Prune the working tree, that is remove the git data structures on disk.
///
/// Throws a [LibGit2Error] if error occured.
void prune(Pointer<git_worktree> wt) {
final error = libgit2.git_worktree_prune(wt, nullptr);
if (error < 0) {
throw LibGit2Error(libgit2.git_error_last());
}
libgit2.git_worktree_prune(wt, nullptr);
}
/// List names of linked working trees.
@ -143,18 +122,8 @@ String path(Pointer<git_worktree> wt) {
///
/// A worktree may be locked if the linked working tree is stored on a portable
/// device which is not available.
///
/// Throws a [LibGit2Error] if error occured.
bool isLocked(Pointer<git_worktree> wt) {
final result = libgit2.git_worktree_is_locked(nullptr, wt);
if (result < 0) {
throw LibGit2Error(libgit2.git_error_last());
} else if (result == 0) {
return false;
} else {
return true;
}
return libgit2.git_worktree_is_locked(nullptr, wt) == 1 ? true : false;
}
/// Lock worktree if not already locked.

View file

@ -90,7 +90,7 @@ class Blob {
final result = patch_bindings.fromBlobs(
oldBlobPointer: _blobPointer,
oldAsPath: oldAsPath,
newBlobPointer: newBlob?.pointer,
newBlobPointer: newBlob?.pointer ?? nullptr,
newAsPath: newAsPath,
flags: flags.fold(0, (acc, e) => acc | e.value),
contextLines: contextLines,

View file

@ -37,29 +37,26 @@ class Branch {
);
}
/// Lookups a branch by its [name] in a [repo]sitory.
/// Lookups a branch by its [name] and [type] in a [repo]sitory.
///
/// The branch name will be checked for validity.
///
/// Should be freed with [free] to release allocated memory when no longer
/// needed.
/// If branch [type] is [GitBranch.remote] you must include the remote name
/// in the [name] (e.g. "origin/master").
///
/// Should be freed to release allocated memory when no longer needed.
///
/// Throws a [LibGit2Error] if error occured.
Branch.lookup({required Repository repo, required String name}) {
final ref = Reference(
reference_bindings.lookupDWIM(
repoPointer: repo.pointer,
name: name,
),
);
Branch.lookup({
required Repository repo,
required String name,
GitBranch type = GitBranch.local,
}) {
_branchPointer = bindings.lookup(
repoPointer: repo.pointer,
branchName: name,
branchType: ref.isBranch ? GitBranch.local.value : GitBranch.remote.value,
branchType: type.value,
);
ref.free();
}
late final Pointer<git_reference> _branchPointer;

View file

@ -80,8 +80,6 @@ class Commit {
Signature get author => Signature(bindings.author(_commitPointer));
/// Returns list of parent commits [Oid]s.
///
/// Throws a [LibGit2Error] if error occured.
List<Oid> get parents {
var parents = <Oid>[];
final parentCount = bindings.parentCount(_commitPointer);
@ -114,3 +112,29 @@ class Commit {
'time: $time, committer: $committer, author: $author}';
}
}
/// An annotated commit contains information about how it was looked up, which may be useful
/// for functions like merge or rebase to provide context to the operation. For example, conflict
/// files will include the name of the source or target branches being merged.
///
/// Note: for internal use.
class AnnotatedCommit {
/// Lookups an annotated commit from the given commit [oid]. The resulting annotated commit
/// must be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
AnnotatedCommit.lookup({required Repository repo, required Oid oid}) {
_annotatedCommitPointer = bindings.annotatedLookup(
repoPointer: repo.pointer,
oidPointer: oid.pointer,
);
}
late final Pointer<Pointer<git_annotated_commit>> _annotatedCommitPointer;
/// Pointer to pointer to memory address for allocated commit object.
Pointer<Pointer<git_annotated_commit>> get pointer => _annotatedCommitPointer;
/// Releases memory allocated for commit object.
void free() => bindings.annotatedFree(_annotatedCommitPointer.value);
}

View file

@ -13,6 +13,15 @@ class Diff {
/// Should be freed with `free()` to release allocated memory.
Diff(this._diffPointer);
/// Reads the contents of a git patch file into a git diff object.
///
/// The diff object produced is similar to the one that would be produced if you actually
/// produced it computationally by comparing two trees, however there may be subtle differences.
/// For example, a patch file likely contains abbreviated object IDs, so the object IDs in a
/// diff delta produced by this function will also be abbreviated.
///
/// This function will only read patch files created by a git implementation, it will not
/// read unified diffs produced by the `diff` program, nor any other types of patch files.
Diff.parse(String content) {
libgit2.git_libgit2_init();
_diffPointer = bindings.parse(content);
@ -63,7 +72,9 @@ class Diff {
patch.free();
}
final result = buffer.ref.ptr.cast<Utf8>().toDartString();
final result = buffer.ref.ptr == nullptr
? ''
: buffer.ref.ptr.cast<Utf8>().toDartString();
calloc.free(buffer);
return result;
}
@ -115,7 +126,7 @@ class Diff {
/// and should in fact generate the same IDs as the upstream git project does.
///
/// Throws a [LibGit2Error] if error occured.
Oid get patchId => Oid(bindings.patchId(_diffPointer));
Oid get patchOid => Oid(bindings.patchOid(_diffPointer));
/// Releases memory allocated for diff object.
void free() => bindings.free(_diffPointer);
@ -301,8 +312,6 @@ class DiffHunk {
}
/// Returns list of lines in a hunk of a patch.
///
/// Throws a [LibGit2Error] if error occured.
List<DiffLine> get lines {
var lines = <DiffLine>[];
for (var i = 0; i < linesCount; i++) {

View file

@ -131,8 +131,6 @@ class Index with IterableMixin<IndexEntry> {
/// if it has changed since the last time it was loaded. Purely in-memory index data
/// will be untouched. Be aware: if there are changes on disk, unwritten in-memory changes
/// are discarded.
///
/// Throws a [LibGit2Error] if error occured.
void read({bool force = true}) =>
bindings.read(indexPointer: _indexPointer, force: force);
@ -143,8 +141,6 @@ class Index with IterableMixin<IndexEntry> {
}
/// Writes an existing index object from memory back to disk using an atomic file lock.
///
/// Throws a [LibGit2Error] if error occured.
void write() => bindings.write(_indexPointer);
/// Writes the index as a tree.
@ -180,8 +176,6 @@ class Index with IterableMixin<IndexEntry> {
bindings.removeAll(indexPointer: _indexPointer, pathspec: path);
/// Creates a diff between the repository index and the workdir directory.
///
/// Throws a [LibGit2Error] if error occured.
Diff diffToWorkdir({
Set<GitDiff> flags = const {GitDiff.normal},
int contextLines = 3,
@ -197,8 +191,6 @@ class Index with IterableMixin<IndexEntry> {
}
/// Creates a diff between a tree and repository index.
///
/// Throws a [LibGit2Error] if error occured.
Diff diffToTree({
required Tree tree,
Set<GitDiff> flags = const {GitDiff.normal},

View file

@ -9,8 +9,6 @@ class Mailmap {
///
/// This object is empty, so you'll have to add a mailmap file before you can
/// do anything with it. Must be freed with `free()`.
///
/// Throws a [LibGit2Error] if error occured.
Mailmap.empty() {
libgit2.git_libgit2_init();
@ -20,8 +18,6 @@ class Mailmap {
/// Initializes a new instance of [Mailmap] class from provided buffer.
///
/// Must be freed with `free()`.
///
/// Throws a [LibGit2Error] if error occured.
Mailmap.fromBuffer(String buffer) {
libgit2.git_libgit2_init();
@ -50,8 +46,6 @@ class Mailmap {
/// Returns list containing resolved [name] and [email] to the corresponding real name
/// and real email respectively.
///
/// Throws a [LibGit2Error] if error occured.
List<String> resolve({
required String name,
required String email,
@ -64,8 +58,6 @@ class Mailmap {
}
/// Resolves a signature to use real names and emails with a mailmap.
///
/// Throws a [LibGit2Error] if error occured.
Signature resolveSignature(Signature signature) {
return Signature(bindings.resolveSignature(
mailmapPointer: _mailmapPointer,
@ -76,20 +68,24 @@ class Mailmap {
/// Adds a single entry to the given mailmap object. If the entry already exists,
/// it will be replaced with the new entry.
///
/// Throws a [LibGit2Error] if error occured.
/// Throws a [ArgumentError] if [replaceEmail] is empty string.
void addEntry({
String? realName,
String? realEmail,
String? replaceName,
required String replaceEmail,
}) {
bindings.addEntry(
mailmapPointer: _mailmapPointer,
realName: realName,
realEmail: realEmail,
replaceName: replaceName,
replaceEmail: replaceEmail,
);
if (replaceEmail.trim().isEmpty) {
throw ArgumentError.value('replaceEmail can\'t be empty');
} else {
bindings.addEntry(
mailmapPointer: _mailmapPointer,
realName: realName,
realEmail: realEmail,
replaceName: replaceName,
replaceEmail: replaceEmail,
);
}
}
/// Releases memory allocated for mailmap object.

View file

@ -14,8 +14,6 @@ class Odb {
///
/// Before the ODB can be used for read/writing, a custom database backend must be
/// manually added.
///
/// Throws a [LibGit2Error] if error occured.
Odb.create() {
libgit2.git_libgit2_init();
@ -36,8 +34,6 @@ class Odb {
/// have been exhausted.
///
/// Writing is disabled on alternate backends.
///
/// Throws a [LibGit2Error] if error occured.
void addDiskAlternate(String path) {
bindings.addDiskAlternate(
odbPointer: _odbPointer,

View file

@ -9,7 +9,7 @@ class Patch {
/// Initializes a new instance of [Patch] class from provided
/// pointer to patch object in memory and pointers to old and new blobs/buffers.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
Patch(this._patchPointer, this._aPointer, this._bPointer);
/// Directly generates a patch from the difference between two blobs, buffers or
@ -17,9 +17,7 @@ class Patch {
///
/// [a] and [b] can be [Blob], [String] or null.
///
/// Should be freed with `free()` to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
/// Should be freed to release allocated memory.
Patch.create({
required Object? a,
required Object? b,
@ -35,11 +33,11 @@ class Patch {
var result = <String, Pointer?>{};
if (a is Blob?) {
if (b is Blob) {
if (b is Blob?) {
result = bindings.fromBlobs(
oldBlobPointer: a?.pointer ?? nullptr,
oldAsPath: aPath,
newBlobPointer: b.pointer,
newBlobPointer: b?.pointer ?? nullptr,
newAsPath: bPath,
flags: flagsInt,
contextLines: contextLines,
@ -49,7 +47,7 @@ class Patch {
result = bindings.fromBlobAndBuffer(
oldBlobPointer: a?.pointer,
oldAsPath: aPath,
buffer: b,
buffer: b as String?,
bufferAsPath: bPath,
flags: flagsInt,
contextLines: contextLines,
@ -126,8 +124,6 @@ class Patch {
DiffDelta get delta => DiffDelta(bindings.delta(_patchPointer));
/// Returns the list of hunks in a patch.
///
/// Throws a [LibGit2Error] if error occured.
List<DiffHunk> get hunks {
final length = bindings.numHunks(_patchPointer);
final hunks = <DiffHunk>[];
@ -157,5 +153,5 @@ class Patch {
}
@override
String toString() => 'Patch{size: $size, delta: $delta}';
String toString() => 'Patch{size: ${size()}, delta: $delta}';
}

View file

@ -2,7 +2,6 @@ import 'dart:ffi';
import 'package:libgit2dart/libgit2dart.dart';
import 'bindings/libgit2_bindings.dart';
import 'bindings/rebase.dart' as bindings;
import 'bindings/commit.dart' as commit_bindings;
class Rebase {
/// Initializes a new instance of the [Rebase] class by initializing a
@ -25,38 +24,33 @@ class Rebase {
Oid? upstream,
Oid? onto,
}) {
Pointer<git_annotated_commit>? _branch, _upstream, _onto;
AnnotatedCommit? _branch, _upstream, _onto;
if (branch != null) {
_branch = commit_bindings
.annotatedLookup(
repoPointer: repo.pointer,
oidPointer: branch.pointer,
)
.value;
_branch = AnnotatedCommit.lookup(repo: repo, oid: branch);
}
if (upstream != null) {
_upstream = commit_bindings
.annotatedLookup(
repoPointer: repo.pointer,
oidPointer: upstream.pointer,
)
.value;
_upstream = AnnotatedCommit.lookup(repo: repo, oid: upstream);
}
if (onto != null) {
_onto = commit_bindings
.annotatedLookup(
repoPointer: repo.pointer,
oidPointer: onto.pointer,
)
.value;
_onto = AnnotatedCommit.lookup(repo: repo, oid: onto);
}
_rebasePointer = bindings.init(
repoPointer: repo.pointer,
branchPointer: _branch,
upstreamPointer: _upstream,
ontoPointer: _onto,
branchPointer: _branch?.pointer.value,
upstreamPointer: _upstream?.pointer.value,
ontoPointer: _onto?.pointer.value,
);
if (branch != null) {
_branch!.free();
}
if (upstream != null) {
_upstream!.free();
}
if (onto != null) {
_onto!.free();
}
}
/// Pointer to memory address for allocated rebase object.
@ -96,14 +90,10 @@ class Rebase {
}
/// Finishes a rebase that is currently in progress once all patches have been applied.
///
/// Throws a [LibGit2Error] if error occured.
void finish() => bindings.finish(_rebasePointer);
/// Aborts a rebase that is currently in progress, resetting the repository and working
/// directory to their state before rebase began.
///
/// Throws a [LibGit2Error] if error occured.
void abort() => bindings.abort(_rebasePointer);
/// Releases memory allocated for rebase object.

View file

@ -80,8 +80,6 @@ class Reference {
/// Deletes an existing reference with provided [name].
///
/// This method works for both direct and symbolic references.
///
/// Throws a [LibGit2Error] if error occured.
static void delete({required Repository repo, required String name}) {
final ref = Reference.lookup(repo: repo, name: name);
bindings.delete(ref.pointer);
@ -226,8 +224,6 @@ class Reference {
String get shorthand => bindings.shorthand(_refPointer);
/// Checks if a reflog exists for the specified reference [name].
///
/// Throws a [LibGit2Error] if error occured.
bool get hasLog {
return bindings.hasLog(
repoPointer: bindings.owner(_refPointer),

View file

@ -6,8 +6,6 @@ import 'bindings/reflog.dart' as bindings;
class RefLog with IterableMixin<RefLogEntry> {
/// Initializes a new instance of [RefLog] class from provided [Reference].
///
/// Throws a [LibGit2Error] if error occured.
RefLog(Reference ref) {
_reflogPointer = bindings.read(
repoPointer: ref.owner.pointer,

View file

@ -80,8 +80,6 @@ class Remote {
}
/// Returns a list of the configured remotes for a [repo]sitory.
///
/// Throws a [LibGit2Error] if error occured.
static List<String> list(Repository repo) {
return bindings.list(repo.pointer);
}
@ -184,11 +182,19 @@ class Remote {
/// Get the remote's list of push refspecs.
List<String> get pushRefspecs => bindings.pushRefspecs(_remotePointer);
/// Get the remote repository's reference advertisement list.
/// Returns the remote repository's reference list and their associated commit ids.
///
/// [proxy] can be 'auto' to try to auto-detect the proxy from the git configuration or some
/// specified url. By default connection isn't done through proxy.
///
/// Returned map keys:
/// - `local` is true if remote head is available locally, false otherwise.
/// - `loid` is the oid of the object the local copy of the remote head is currently
/// pointing to. null if there is no local copy of the remote head.
/// - `name` is the name of the reference.
/// - `oid` is the oid of the object the remote head is currently pointing to.
/// - `symref` is the target of the symbolic reference or empty string.
///
/// Throws a [LibGit2Error] if error occured.
List<Map<String, Object?>> ls({
String? proxy,

View file

@ -120,8 +120,6 @@ class Repository {
/// the first repository is found, or when reaching a directory referenced in [ceilingDirs].
///
/// The method will automatically detect if the repository is bare (if there is a repository).
///
/// Throws a [LibGit2Error] if error occured.
static String discover({required String startPath, String? ceilingDirs}) {
return bindings.discover(
startPath: startPath,
@ -164,8 +162,6 @@ class Repository {
/// under refs/namespaces/foo/, use foo as the namespace.
///
/// Pass null to unset.
///
/// Throws a [LibGit2Error] if error occured.
void setNamespace(String? namespace) {
bindings.setNamespace(
repoPointer: _repoPointer,
@ -322,8 +318,6 @@ class Repository {
/// will be returned, including global and system configurations (if they are available).
///
/// The configuration file must be freed once it's no longer being used by the user.
///
/// Throws a [LibGit2Error] if error occured.
Config get config => Config(bindings.config(_repoPointer));
/// Returns a snapshot of the repository's configuration.
@ -332,8 +326,6 @@ class Repository {
/// The contents of this snapshot will not change, even if the underlying config files are modified.
///
/// The configuration file must be freed once it's no longer being used by the user.
///
/// Throws a [LibGit2Error] if error occured.
Config get configSnapshot => Config(bindings.configSnapshot(_repoPointer));
/// Returns [Reference] object pointing to repository head.
@ -451,8 +443,6 @@ class Repository {
///
/// This looks up the user.name and user.email from the configuration and uses the
/// current time as the timestamp, and creates a new signature based on that information.
///
/// Throws a [LibGit2Error] if error occured.
Signature get defaultSignature => Signature.defaultSignature(this);
/// Returns the list of commits starting from provided commit [oid].
@ -648,15 +638,21 @@ class Repository {
List<Branch> get branchesRemote =>
Branch.list(repo: this, type: GitBranch.remote);
/// Lookups a branch by its [name] in a repository.
/// Lookups a branch by its [name] and [type] in a repository.
///
/// The branch name will be checked for validity.
/// The branch [name] will be checked for validity.
///
/// If branch [type] is [GitBranch.remote] you must include the remote name
/// in the [name] (e.g. "origin/master").
///
/// Should be freed to release allocated memory when no longer needed.
///
/// Throws a [LibGit2Error] if error occured.
Branch lookupBranch(String name) {
return Branch.lookup(repo: this, name: name);
Branch lookupBranch({
required String name,
GitBranch type = GitBranch.local,
}) {
return Branch.lookup(repo: this, name: name, type: type);
}
/// Creates a new branch pointing at a [target] commit.
@ -706,6 +702,8 @@ class Repository {
/// Checks status of the repository and returns map of file paths and their statuses.
///
/// Returns empty map if there are no changes in statuses.
///
/// Throws a [LibGit2Error] if error occured.
Map<String, Set<GitStatus>> get status {
var result = <String, Set<GitStatus>>{};
var list = status_bindings.listNew(_repoPointer);
@ -789,14 +787,14 @@ class Repository {
String ourRef = 'HEAD',
}) {
final ref = lookupReference(ourRef);
final head = commit_bindings.annotatedLookup(
repoPointer: _repoPointer,
oidPointer: theirHead.pointer,
final head = AnnotatedCommit.lookup(
repo: this,
oid: theirHead,
);
final analysisInt = merge_bindings.analysis(
repoPointer: _repoPointer,
ourRefPointer: ref.pointer,
theirHeadPointer: head,
theirHeadPointer: head.pointer,
theirHeadsLen: 1,
);
@ -807,7 +805,7 @@ class Repository {
(e) => analysisInt[1] == e.value,
);
commit_bindings.annotatedFree(head.value);
head.free();
ref.free();
return [analysisSet, mergePreference];
@ -820,18 +818,18 @@ class Repository {
///
/// Throws a [LibGit2Error] if error occured.
void merge(Oid oid) {
final theirHead = commit_bindings.annotatedLookup(
repoPointer: _repoPointer,
oidPointer: oid.pointer,
final theirHead = AnnotatedCommit.lookup(
repo: this,
oid: oid,
);
merge_bindings.merge(
repoPointer: _repoPointer,
theirHeadsPointer: theirHead,
theirHeadsPointer: theirHead.pointer,
theirHeadsLen: 1,
);
commit_bindings.annotatedFree(theirHead.value);
theirHead.free();
}
/// Merges two files as they exist in the index, using the given common ancestor
@ -1092,23 +1090,30 @@ class Repository {
return a.diff(newBlob: b, oldAsPath: aPath, newAsPath: bPath);
}
/// Applies the [diff] to the given repository, making changes directly in the working directory.
/// Applies the [diff] to the given repository, making changes directly in the
/// working directory (default), the index, or both.
///
/// Throws a [LibGit2Error] if error occured.
void apply(Diff diff) {
void apply({
required Diff diff,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
diff_bindings.apply(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
location: GitApplyLocation.workdir.value,
location: location.value,
);
}
/// Checks if the [diff] will apply to HEAD.
bool applies(Diff diff) {
/// Checks if the [diff] will apply to the working directory (default), the index, or both.
bool applies({
required Diff diff,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
return diff_bindings.apply(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
location: GitApplyLocation.index.value,
location: location.value,
check: true,
);
}
@ -1162,7 +1167,7 @@ class Repository {
/// Removes a single stashed state from the stash list.
///
/// Throws a [LibGit2Error] if error occured.
void dropStash([int index = 0]) {
void dropStash({int index = 0}) {
Stash.drop(repo: this, index: index);
}
@ -1191,8 +1196,6 @@ class Repository {
}
/// Returns a list of the configured remotes for a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get remotes => Remote.list(this);
/// Lookups remote with provided [name].
@ -1246,8 +1249,6 @@ class Repository {
///
/// Returned value can be either `true`, `false`, `null` (if the attribute was not set at all),
/// or a [String] value, if the attribute was set to an actual string.
///
/// Throws a [LibGit2Error] if error occured.
Object? getAttribute({
required String path,
required String name,
@ -1511,8 +1512,6 @@ class Repository {
}
/// Returns a list with all tracked submodules paths of a repository.
///
/// Throws a [LibGit2Error] if error occured.
List<String> get submodules => Submodule.list(this);
/// Lookups submodule by name or path.

View file

@ -28,8 +28,6 @@ class RevWalk {
/// Changes the sorting mode when iterating through the repository's contents.
///
/// Changing the sorting mode resets the walker.
///
/// Throws a [LibGit2Error] if error occured.
void sorting(Set<GitSort> sorting) {
bindings.sorting(
walkerPointer: _revWalkPointer,
@ -79,8 +77,6 @@ class RevWalk {
/// Simplify the history by first-parent.
///
/// No parents other than the first for each commit will be enqueued.
///
/// Throws a [LibGit2Error] if error occured.
void simplifyFirstParent() => bindings.simplifyFirstParent(_revWalkPointer);
/// Releases memory allocated for [RevWalk] object.

View file

@ -9,7 +9,7 @@ class Signature {
/// Initializes a new instance of [Signature] class from provided pointer to
/// signature object in memory.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
Signature(this._signaturePointer);
/// Initializes a new instance of [Signature] class from provided [name], [email],
@ -17,7 +17,7 @@ class Signature {
///
/// If [time] isn't provided [Signature] will be created with a timestamp of 'now'.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
Signature.create({
required String name,
required String email,
@ -47,8 +47,6 @@ class Signature {
///
/// This looks up the user.name and user.email from the configuration and uses the
/// current time as the timestamp, and creates a new signature based on that information.
///
/// Throws a [LibGit2Error] if error occured.
static Signature defaultSignature(Repository repo) =>
Signature(bindings.defaultSignature(repo.pointer));

View file

@ -108,16 +108,13 @@ class Submodule {
}
/// Returns a list with all tracked submodules paths of a repository.
///
/// Throws a [LibGit2Error] if error occured.
static List<String> list(Repository repo) => bindings.list(repo.pointer);
/// Opens the repository for a submodule.
///
/// This is a newly opened repository object. The caller is responsible for calling
/// `free()` on it when done. Multiple calls to this function will return distinct
/// git repository objects. This will only work if the submodule is checked out into
/// the working directory.
/// This is a newly opened repository object. The caller is responsible for freeing it
/// when done. Multiple calls to this function will return distinct git repository objects.
/// This will only work if the submodule is checked out into the working directory.
///
/// Throws a [LibGit2Error] if error occured.
Repository open() {
@ -129,8 +126,6 @@ class Submodule {
/// This looks at a submodule and tries to determine the status. How deeply it examines
/// the working directory to do this will depend on the combination of [GitSubmoduleIgnore]
/// values provided to [ignore] .
///
/// Throws a [LibGit2Error] if error occured.
Set<GitSubmoduleStatus> status({
GitSubmoduleIgnore ignore = GitSubmoduleIgnore.unspecified,
}) {
@ -151,8 +146,6 @@ class Submodule {
/// config, acting like `git submodule sync`. This is useful if you have altered the URL
/// for the submodule (or it has been altered by a fetch of upstream changes) and you
/// need to update your local repo.
///
/// Throws a [LibGit2Error] if error occured.
void sync() => bindings.sync(_submodulePointer);
/// Rereads submodule info from config, index, and HEAD.
@ -181,8 +174,6 @@ class Submodule {
///
/// After calling this, you may wish to call [sync] to write the changes to
/// the checked out submodule repository.
///
/// Throws a [LibGit2Error] if error occured.
set url(String url) {
bindings.setUrl(
repoPointer: bindings.owner(_submodulePointer),
@ -198,8 +189,6 @@ class Submodule {
///
/// After calling this, you may wish to call [sync] to write the changes to
/// the checked out submodule repository.
///
/// Throws a [LibGit2Error] if error occured.
set branch(String branch) {
bindings.setBranch(
repoPointer: bindings.owner(_submodulePointer),
@ -243,8 +232,6 @@ class Submodule {
/// Sets the ignore rule for the submodule in the configuration.
///
/// This does not affect any currently-loaded instances.
///
/// Throws a [LibGit2Error] if error occured.
set ignore(GitSubmoduleIgnore ignore) {
final repo = bindings.owner(_submodulePointer);
bindings.setIgnore(repoPointer: repo, name: name, ignore: ignore.value);
@ -261,8 +248,6 @@ class Submodule {
/// Sets the update rule for the submodule in the configuration.
///
/// This setting won't affect any existing instances.
///
/// Throws a [LibGit2Error] if error occured.
set updateRule(GitSubmoduleUpdate rule) {
bindings.setUpdateRule(
repoPointer: bindings.owner(_submodulePointer),

View file

@ -93,8 +93,6 @@ class Tree {
}
/// Creates a diff between a tree and repository index.
///
/// Throws a [LibGit2Error] if error occured.
Diff diffToIndex({
required Index index,
Set<GitDiff> flags = const {GitDiff.normal},

View file

@ -24,13 +24,9 @@ class TreeBuilder {
int get length => bindings.entryCount(_treeBuilderPointer);
/// Writes the contents of the tree builder as a tree object.
///
/// Throws a [LibGit2Error] if error occured.
Oid write() => Oid(bindings.write(_treeBuilderPointer));
/// Clears all the entires in the tree builder.
///
/// Throws a [LibGit2Error] if error occured.
void clear() => bindings.clear(_treeBuilderPointer);
/// Returns an entry from the tree builder from its filename.

View file

@ -1,3 +1,5 @@
// coverage:ignore-file
import 'dart:io';
import 'dart:ffi';
import 'bindings/libgit2_bindings.dart';

View file

@ -11,7 +11,7 @@ class Worktree {
/// If [ref] is provided, no new branch will be created but specified [ref] will
/// be used instead.
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Worktree.create({
@ -31,7 +31,7 @@ class Worktree {
/// Initializes a new instance of [Worktree] class by looking up existing worktree
/// with provided [Repository] object and worktree [name].
///
/// Should be freed with `free()` to release allocated memory.
/// Should be freed to release allocated memory.
///
/// Throws a [LibGit2Error] if error occured.
Worktree.lookup({required Repository repo, required String name}) {
@ -56,8 +56,6 @@ class Worktree {
///
/// A worktree may be locked if the linked working tree is stored on a portable
/// device which is not available.
///
/// Throws a [LibGit2Error] if error occured.
bool get isLocked => bindings.isLocked(_worktreePointer);
/// Locks worktree if not already locked.
@ -78,8 +76,6 @@ class Worktree {
/// Prunes working tree.
///
/// Prune the working tree, that is remove the git data structures on disk.
///
/// Throws a [LibGit2Error] if error occured.
void prune() => bindings.prune(_worktreePointer);
/// Checks if worktree is valid.