feat(diff): add more bindings and api methods (#18)

This commit is contained in:
Aleksey Kulikov 2021-12-14 12:53:17 +03:00 committed by GitHub
parent 6c1735d67d
commit b3e9f6dd1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 238 additions and 29 deletions

View file

@ -1362,27 +1362,56 @@ class Repository {
/// [location] (directly in the working directory (default), the index or
/// both).
///
/// [hunkIndex] is optional index of the hunk to apply.
///
/// Throws a [LibGit2Error] if error occured.
void apply({
required Diff diff,
int? hunkIndex,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
diff_bindings.apply(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
hunkIndex: hunkIndex,
location: location.value,
);
}
/// Applies the [diff] to the [tree], and returns the resulting image as an
/// index.
///
/// [hunkIndex] is optional index of the hunk to apply.
///
/// Throws a [LibGit2Error] if error occured.
Index applyToTree({
required Diff diff,
required Tree tree,
int? hunkIndex,
}) {
return Index(
diff_bindings.applyToTree(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
treePointer: tree.pointer,
hunkIndex: hunkIndex,
),
);
}
/// Checks if the [diff] will apply to provided [location] (the working
/// directory (default), the index or both).
///
/// [hunkIndex] is optional index of the hunk to apply.
bool applies({
required Diff diff,
int? hunkIndex,
GitApplyLocation location = GitApplyLocation.workdir,
}) {
return diff_bindings.apply(
repoPointer: _repoPointer,
diffPointer: diff.pointer,
hunkIndex: hunkIndex,
location: location.value,
check: true,
);