mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-29 18:38:58 +00:00
rebase: allow custom merge_options
Allow callers of rebase to specify custom merge options. This may allow custom conflict resolution, or failing fast when conflicts are detected.
This commit is contained in:
parent
ee6673070a
commit
a202e0d45b
@ -57,6 +57,11 @@ typedef struct {
|
|||||||
*/
|
*/
|
||||||
const char *rewrite_notes_ref;
|
const char *rewrite_notes_ref;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Options to control how trees are merged during `git_rebase_next`.
|
||||||
|
*/
|
||||||
|
git_merge_options merge_options;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Options to control how files are written during `git_rebase_init`,
|
* Options to control how files are written during `git_rebase_init`,
|
||||||
* `git_checkout_next` and `git_checkout_abort`. Note that a minimum
|
* `git_checkout_next` and `git_checkout_abort`. Note that a minimum
|
||||||
@ -110,7 +115,8 @@ typedef enum {
|
|||||||
|
|
||||||
#define GIT_REBASE_OPTIONS_VERSION 1
|
#define GIT_REBASE_OPTIONS_VERSION 1
|
||||||
#define GIT_REBASE_OPTIONS_INIT \
|
#define GIT_REBASE_OPTIONS_INIT \
|
||||||
{GIT_REBASE_OPTIONS_VERSION, 0, 0, NULL, GIT_CHECKOUT_OPTIONS_INIT}
|
{ GIT_REBASE_OPTIONS_VERSION, 0, 0, NULL, GIT_MERGE_OPTIONS_INIT, \
|
||||||
|
GIT_CHECKOUT_OPTIONS_INIT}
|
||||||
|
|
||||||
/** Indicates that a rebase operation is not (yet) in progress. */
|
/** Indicates that a rebase operation is not (yet) in progress. */
|
||||||
#define GIT_REBASE_NO_OPERATION SIZE_MAX
|
#define GIT_REBASE_NO_OPERATION SIZE_MAX
|
||||||
|
@ -813,7 +813,7 @@ static int rebase_next_merge(
|
|||||||
if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 ||
|
if ((error = git_indexwriter_init_for_operation(&indexwriter, rebase->repo, &checkout_opts.checkout_strategy)) < 0 ||
|
||||||
(error = rebase_setupfile(rebase, MSGNUM_FILE, -1, "%" PRIuZ "\n", rebase->current+1)) < 0 ||
|
(error = rebase_setupfile(rebase, MSGNUM_FILE, -1, "%" PRIuZ "\n", rebase->current+1)) < 0 ||
|
||||||
(error = rebase_setupfile(rebase, CURRENT_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0 ||
|
(error = rebase_setupfile(rebase, CURRENT_FILE, -1, "%.*s\n", GIT_OID_HEXSZ, current_idstr)) < 0 ||
|
||||||
(error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, NULL)) < 0 ||
|
(error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0 ||
|
||||||
(error = git_merge__check_result(rebase->repo, index)) < 0 ||
|
(error = git_merge__check_result(rebase->repo, index)) < 0 ||
|
||||||
(error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0 ||
|
(error = git_checkout_index(rebase->repo, index, &checkout_opts)) < 0 ||
|
||||||
(error = git_indexwriter_commit(&indexwriter)) < 0)
|
(error = git_indexwriter_commit(&indexwriter)) < 0)
|
||||||
@ -853,7 +853,7 @@ static int rebase_next_inmemory(
|
|||||||
(error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
|
(error = git_commit_parent(&parent_commit, current_commit, 0)) < 0 ||
|
||||||
(error = git_commit_tree(&parent_tree, parent_commit)) < 0 ||
|
(error = git_commit_tree(&parent_tree, parent_commit)) < 0 ||
|
||||||
(error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 ||
|
(error = git_commit_tree(&head_tree, rebase->last_commit)) < 0 ||
|
||||||
(error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, NULL)) < 0)
|
(error = git_merge_trees(&index, rebase->repo, parent_tree, head_tree, current_tree, &rebase->options.merge_options)) < 0)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
git_index_free(rebase->last_index);
|
git_index_free(rebase->last_index);
|
||||||
|
@ -565,3 +565,33 @@ void test_rebase_merge__custom_checkout_options(void)
|
|||||||
git_reference_free(upstream_ref);
|
git_reference_free(upstream_ref);
|
||||||
git_rebase_free(rebase);
|
git_rebase_free(rebase);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_rebase_merge__custom_merge_options(void)
|
||||||
|
{
|
||||||
|
git_rebase *rebase;
|
||||||
|
git_reference *branch_ref, *upstream_ref;
|
||||||
|
git_annotated_commit *branch_head, *upstream_head;
|
||||||
|
git_rebase_options rebase_options = GIT_REBASE_OPTIONS_INIT;
|
||||||
|
git_rebase_operation *rebase_operation;
|
||||||
|
|
||||||
|
rebase_options.merge_options.flags |=
|
||||||
|
GIT_MERGE_FAIL_ON_CONFLICT |
|
||||||
|
GIT_MERGE_SKIP_REUC;
|
||||||
|
|
||||||
|
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/asparagus"));
|
||||||
|
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/master"));
|
||||||
|
|
||||||
|
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
|
||||||
|
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
|
||||||
|
|
||||||
|
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &rebase_options));
|
||||||
|
|
||||||
|
cl_git_fail_with(GIT_EMERGECONFLICT, git_rebase_next(&rebase_operation, rebase));
|
||||||
|
|
||||||
|
git_annotated_commit_free(branch_head);
|
||||||
|
git_annotated_commit_free(upstream_head);
|
||||||
|
git_reference_free(branch_ref);
|
||||||
|
git_reference_free(upstream_ref);
|
||||||
|
git_rebase_free(rebase);
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user