merge: add simple recursive test

Add a simple recursive test - where multiple ancestors exist and
creating a virtual merge base from them would prevent a conflict.
This commit is contained in:
Edward Thomson 2015-10-22 20:20:07 -04:00 committed by Edward Thomson
parent fa78782f67
commit 86c8d02c07
71 changed files with 125 additions and 6 deletions

View File

@ -73,17 +73,25 @@ typedef enum {
*/ */
GIT_MERGE_FIND_RENAMES = (1 << 0), GIT_MERGE_FIND_RENAMES = (1 << 0),
/**
* Do not write the REUC extension on the generated index
*/
GIT_MERGE_SKIP_REUC = (1 << 2),
/** /**
* If a conflict occurs, exit immediately instead of attempting to * If a conflict occurs, exit immediately instead of attempting to
* continue resolving conflicts. The merge operation will fail with * continue resolving conflicts. The merge operation will fail with
* GIT_EMERGECONFLICT and no index will be returned. * GIT_EMERGECONFLICT and no index will be returned.
*/ */
GIT_MERGE_FAIL_ON_CONFLICT = (1 << 1), GIT_MERGE_FAIL_ON_CONFLICT = (1 << 1),
/**
* Do not write the REUC extension on the generated index
*/
GIT_MERGE_SKIP_REUC = (1 << 2),
/**
* If the commits being merged have multiple merge bases, do not build
* a recursive merge base (by merging the multiple merge bases),
* instead simply use the first base. This flag provides a similar
* merge base to `git-merge-resolve`.
*/
GIT_MERGE_NO_RECURSIVE = (1 << 3),
} git_merge_flag_t; } git_merge_flag_t;
/** /**

View File

@ -4,6 +4,7 @@
#include "tree.h" #include "tree.h"
#include "merge_helpers.h" #include "merge_helpers.h"
#include "merge.h" #include "merge.h"
#include "index.h"
#include "git2/merge.h" #include "git2/merge.h"
#include "git2/sys/index.h" #include "git2/sys/index.h"
#include "git2/annotated_commit.h" #include "git2/annotated_commit.h"
@ -239,7 +240,7 @@ int merge_test_index(git_index *index, const struct merge_index_entry expected[]
const git_index_entry *index_entry; const git_index_entry *index_entry;
/* /*
dump_index_entries(&index->entries); merge__dump_index_entries(&index->entries);
*/ */
if (git_index_entrycount(index) != expected_len) if (git_index_entrycount(index) != expected_len)

View File

@ -0,0 +1,110 @@
#include "clar_libgit2.h"
#include "git2/repository.h"
#include "git2/merge.h"
#include "merge.h"
#include "../merge_helpers.h"
static git_repository *repo;
#define TEST_REPO_PATH "merge-recursive"
void test_merge_trees_recursive__initialize(void)
{
repo = cl_git_sandbox_init(TEST_REPO_PATH);
}
void test_merge_trees_recursive__cleanup(void)
{
cl_git_sandbox_cleanup();
}
void test_merge_trees_recursive__one(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "dea7215f259b2cced87d1bda6c72f8b4ce37a2ff", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchA-1", "branchA-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__one_norecursive(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "dea7215f259b2cced87d1bda6c72f8b4ce37a2ff", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "94d2c01087f48213bd157222d54edfefd77c9bba", 0, "veal.txt" },
};
opts.flags |= GIT_MERGE_NO_RECURSIVE;
cl_git_pass(merge_commits_from_branches(&index, repo, "branchA-1", "branchA-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__two(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "666ffdfcf1eaa5641fa31064bf2607327e843c09", 0, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchB-1", "branchB-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
}
void test_merge_trees_recursive__two_norecursive(void)
{
git_index *index;
git_merge_options opts = GIT_MERGE_OPTIONS_INIT;
opts.flags |= GIT_MERGE_NO_RECURSIVE;
struct merge_index_entry merge_index_entries[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
{ 0100644, "68f6182f4c85d39e1309d97c7e456156dc9c0096", 0, "beef.txt" },
{ 0100644, "4b7c5650008b2e747fe1809eeb5a1dde0e80850a", 0, "bouilli.txt" },
{ 0100644, "c4e6cca3ec6ae0148ed231f97257df8c311e015f", 0, "gravy.txt" },
{ 0100644, "68af1fc7407fd9addf1701a87eb1c95c7494c598", 0, "oyster.txt" },
{ 0100644, "cb49ad76147f5f9439cbd6133708b76142660660", 1, "veal.txt" },
{ 0100644, "b2a81ead9e722af0099fccfb478cea88eea749a2", 2, "veal.txt" },
{ 0100644, "4e21d2d63357bde5027d1625f5ec6b430cdeb143", 3, "veal.txt" },
};
cl_git_pass(merge_commits_from_branches(&index, repo, "branchB-1", "branchB-2", &opts));
cl_assert(merge_test_index(index, merge_index_entries, 8));
git_index_free(index);
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.