mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
feat(merge): add ability to cherry-pick commit
This commit is contained in:
parent
63dabcdd2c
commit
659e69b1f2
3 changed files with 38 additions and 2 deletions
|
@ -67,11 +67,11 @@ void merge(
|
||||||
int theirHeadsLen,
|
int theirHeadsLen,
|
||||||
) {
|
) {
|
||||||
final mergeOpts = calloc<git_merge_options>(sizeOf<git_merge_options>());
|
final mergeOpts = calloc<git_merge_options>(sizeOf<git_merge_options>());
|
||||||
libgit2.git_merge_options_init(mergeOpts, 1);
|
libgit2.git_merge_options_init(mergeOpts, GIT_MERGE_OPTIONS_VERSION);
|
||||||
|
|
||||||
final checkoutOpts =
|
final checkoutOpts =
|
||||||
calloc<git_checkout_options>(sizeOf<git_checkout_options>());
|
calloc<git_checkout_options>(sizeOf<git_checkout_options>());
|
||||||
libgit2.git_checkout_options_init(checkoutOpts, 1);
|
libgit2.git_checkout_options_init(checkoutOpts, GIT_CHECKOUT_OPTIONS_VERSION);
|
||||||
checkoutOpts.ref.checkout_strategy =
|
checkoutOpts.ref.checkout_strategy =
|
||||||
git_checkout_strategy_t.GIT_CHECKOUT_SAFE +
|
git_checkout_strategy_t.GIT_CHECKOUT_SAFE +
|
||||||
git_checkout_strategy_t.GIT_CHECKOUT_RECREATE_MISSING;
|
git_checkout_strategy_t.GIT_CHECKOUT_RECREATE_MISSING;
|
||||||
|
@ -166,3 +166,19 @@ Pointer<git_index> mergeTrees(
|
||||||
return out.value;
|
return out.value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Cherry-pick the given commit, producing changes in the index and working directory.
|
||||||
|
///
|
||||||
|
/// Throws a [LibGit2Error] if error occured.
|
||||||
|
void cherryPick(Pointer<git_repository> repo, Pointer<git_commit> commit) {
|
||||||
|
final opts = calloc<git_cherrypick_options>(sizeOf<git_cherrypick_options>());
|
||||||
|
libgit2.git_cherrypick_options_init(opts, GIT_CHERRYPICK_OPTIONS_VERSION);
|
||||||
|
opts.ref.checkout_opts.checkout_strategy =
|
||||||
|
git_checkout_strategy_t.GIT_CHECKOUT_SAFE;
|
||||||
|
|
||||||
|
final error = libgit2.git_cherrypick(repo, commit, opts);
|
||||||
|
|
||||||
|
if (error < 0) {
|
||||||
|
throw LibGit2Error(libgit2.git_error_last());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -608,4 +608,14 @@ class Repository {
|
||||||
|
|
||||||
return Index(result);
|
return Index(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Cherry-picks the given commit, producing changes in the index and 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 cherryPick(Commit commit) =>
|
||||||
|
merge_bindings.cherryPick(_repoPointer, commit.pointer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -242,5 +242,15 @@ void main() {
|
||||||
theirCommit.free();
|
theirCommit.free();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('successfully cherry-picks commit', () {
|
||||||
|
final cherry = repo['5aecfa0fb97eadaac050ccb99f03c3fb65460ad4'] as Commit;
|
||||||
|
repo.cherryPick(cherry);
|
||||||
|
expect(repo.state, GitRepositoryState.cherrypick.value);
|
||||||
|
final index = repo.index;
|
||||||
|
expect(index.conflicts, isEmpty);
|
||||||
|
|
||||||
|
index.free();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue