mirror of
https://github.com/libgit2/libgit2.git
synced 2026-06-22 06:26:26 +00:00
Added cherry pick tests
This commit is contained in:
106
tests/cherrypick/bare.c
Normal file
106
tests/cherrypick/bare.c
Normal file
@@ -0,0 +1,106 @@
|
||||
#include "clar.h"
|
||||
#include "clar_libgit2.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "fileops.h"
|
||||
#include "git2/cherrypick.h"
|
||||
|
||||
#include "../merge/merge_helpers.h"
|
||||
|
||||
#define TEST_REPO_PATH "cherrypick"
|
||||
|
||||
static git_repository *repo;
|
||||
|
||||
void test_cherrypick_bare__initialize(void)
|
||||
{
|
||||
repo = cl_git_sandbox_init(TEST_REPO_PATH);
|
||||
}
|
||||
|
||||
void test_cherrypick_bare__cleanup(void)
|
||||
{
|
||||
cl_git_sandbox_cleanup();
|
||||
}
|
||||
|
||||
void test_cherrypick_bare__automerge(void)
|
||||
{
|
||||
git_commit *head = NULL, *commit = NULL;
|
||||
git_index *index = NULL;
|
||||
git_oid head_oid, cherry_oid;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
|
||||
{ 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" },
|
||||
{ 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
|
||||
};
|
||||
|
||||
git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
|
||||
cl_git_pass(git_cherry_pick_commit(&index, repo, commit, head, 0, NULL));
|
||||
cl_assert(merge_test_index(index, merge_index_entries, 3));
|
||||
|
||||
git_index_free(index);
|
||||
git_commit_free(head);
|
||||
git_commit_free(commit);
|
||||
}
|
||||
|
||||
void test_cherrypick_bare__conflicts(void)
|
||||
{
|
||||
git_commit *head = NULL, *commit = NULL;
|
||||
git_index *index = NULL;
|
||||
git_oid head_oid, cherry_oid;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
|
||||
{ 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 1, "file2.txt" },
|
||||
{ 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 2, "file2.txt" },
|
||||
{ 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 3, "file2.txt" },
|
||||
{ 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 1, "file3.txt" },
|
||||
{ 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 2, "file3.txt" },
|
||||
{ 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" },
|
||||
};
|
||||
|
||||
git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
|
||||
cl_git_pass(git_cherry_pick_commit(&index, repo, commit, head, 0, NULL));
|
||||
cl_assert(merge_test_index(index, merge_index_entries, 7));
|
||||
|
||||
git_index_free(index);
|
||||
git_commit_free(head);
|
||||
git_commit_free(commit);
|
||||
}
|
||||
|
||||
void test_cherrypick_bare__orphan(void)
|
||||
{
|
||||
git_commit *head = NULL, *commit = NULL;
|
||||
git_index *index = NULL;
|
||||
git_oid head_oid, cherry_oid;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
|
||||
{ 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" },
|
||||
{ 0100644, "85a4a1d791973644f24c72f5e89420d3064cc452", 0, "file3.txt" },
|
||||
{ 0100644, "9ccb9bf50c011fd58dcbaa65df917bf79539717f", 0, "orphan.txt" },
|
||||
};
|
||||
|
||||
git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "74f06b5bfec6d33d7264f73606b57a7c0b963819");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
|
||||
cl_git_pass(git_cherry_pick_commit(&index, repo, commit, head, 0, NULL));
|
||||
cl_assert(merge_test_index(index, merge_index_entries, 4));
|
||||
|
||||
git_index_free(index);
|
||||
git_commit_free(head);
|
||||
git_commit_free(commit);
|
||||
}
|
||||
|
||||
429
tests/cherrypick/workdir.c
Normal file
429
tests/cherrypick/workdir.c
Normal file
@@ -0,0 +1,429 @@
|
||||
#include "clar.h"
|
||||
#include "clar_libgit2.h"
|
||||
|
||||
#include "buffer.h"
|
||||
#include "fileops.h"
|
||||
#include "git2/cherrypick.h"
|
||||
|
||||
#include "../merge/merge_helpers.h"
|
||||
|
||||
#define TEST_REPO_PATH "cherrypick"
|
||||
|
||||
static git_repository *repo;
|
||||
static git_index *repo_index;
|
||||
|
||||
// Fixture setup and teardown
|
||||
void test_cherrypick_workdir__initialize(void)
|
||||
{
|
||||
repo = cl_git_sandbox_init(TEST_REPO_PATH);
|
||||
git_repository_index(&repo_index, repo);
|
||||
}
|
||||
|
||||
void test_cherrypick_workdir__cleanup(void)
|
||||
{
|
||||
git_index_free(repo_index);
|
||||
cl_git_sandbox_cleanup();
|
||||
}
|
||||
|
||||
/* git reset --hard d3d77487660ee3c0194ee01dc5eaf478782b1c7e
|
||||
* git cherry-pick cfc4f0999a8367568e049af4f72e452d40828a15
|
||||
* git cherry-pick 964ea3da044d9083181a88ba6701de9e35778bf4
|
||||
* git cherry-pick a43a050c588d4e92f11a6b139680923e9728477d
|
||||
*/
|
||||
void test_cherrypick_workdir__automerge(void)
|
||||
{
|
||||
git_oid head_oid;
|
||||
git_signature *signature = NULL;
|
||||
size_t i;
|
||||
|
||||
const char *cherry_pick_oids[] = {
|
||||
"cfc4f0999a8367568e049af4f72e452d40828a15",
|
||||
"964ea3da044d9083181a88ba6701de9e35778bf4",
|
||||
"a43a050c588d4e92f11a6b139680923e9728477d",
|
||||
};
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
|
||||
{ 0100644, "a661b5dec1004e2c62654ded3762370c27cf266b", 0, "file2.txt" },
|
||||
{ 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
|
||||
|
||||
{ 0100644, "38c05a857e831a7e759d83778bfc85d003e21c45", 0, "file1.txt" },
|
||||
{ 0100644, "bd8fc3c59fb52d3c8b5907ace7defa5803f82419", 0, "file2.txt" },
|
||||
{ 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
|
||||
|
||||
{ 0100644, "f06427bee380364bc7e0cb26a9245158e4726ce0", 0, "file1.txt" },
|
||||
{ 0100644, "bd8fc3c59fb52d3c8b5907ace7defa5803f82419", 0, "file2.txt" },
|
||||
{ 0100644, "df6b290e0bd6a89b01d69f66687e8abf385283ca", 0, "file3.txt" },
|
||||
};
|
||||
|
||||
cl_git_pass(git_signature_new(&signature, "Picker", "picker@example.org", time(NULL), 0));
|
||||
|
||||
git_oid_fromstr(&head_oid, "d3d77487660ee3c0194ee01dc5eaf478782b1c7e");
|
||||
|
||||
for (i = 0; i < 3; ++i) {
|
||||
git_commit *head = NULL, *commit = NULL;
|
||||
git_oid cherry_oid, cherry_picked_oid, cherry_picked_tree_oid;
|
||||
git_tree *cherry_picked_tree = NULL;
|
||||
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, cherry_pick_oids[i]);
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
cl_git_pass(git_cherry_pick(repo, commit, NULL));
|
||||
|
||||
cl_assert(git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
|
||||
cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
|
||||
|
||||
cl_git_pass(git_index_write_tree(&cherry_picked_tree_oid, repo_index));
|
||||
cl_git_pass(git_tree_lookup(&cherry_picked_tree, repo, &cherry_picked_tree_oid));
|
||||
cl_git_pass(git_commit_create(&cherry_picked_oid, repo, "HEAD", signature, signature, NULL,
|
||||
"Cherry picked!", cherry_picked_tree, 1, (const git_commit **)&head));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_index_entries + i * 3, 3));
|
||||
|
||||
git_oid_cpy(&head_oid, &cherry_picked_oid);
|
||||
|
||||
git_tree_free(cherry_picked_tree);
|
||||
git_commit_free(head);
|
||||
git_commit_free(commit);
|
||||
}
|
||||
|
||||
git_signature_free(signature);
|
||||
}
|
||||
|
||||
/* git reset --hard bafbf6912c09505ac60575cd43d3f2aba3bd84d8
|
||||
* git cherry-pick e9b63f3655b2ad80c0ff587389b5a9589a3a7110
|
||||
*/
|
||||
void test_cherrypick_workdir__conflicts(void)
|
||||
{
|
||||
git_commit *head = NULL, *commit = NULL;
|
||||
git_oid head_oid, cherry_oid;
|
||||
git_buf conflicting_buf = GIT_BUF_INIT, mergemsg_buf = GIT_BUF_INIT;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
|
||||
{ 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 1, "file2.txt" },
|
||||
{ 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 2, "file2.txt" },
|
||||
{ 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 3, "file2.txt" },
|
||||
{ 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 1, "file3.txt" },
|
||||
{ 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 2, "file3.txt" },
|
||||
{ 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" },
|
||||
};
|
||||
|
||||
git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
|
||||
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
cl_git_pass(git_cherry_pick(repo, commit, NULL));
|
||||
|
||||
cl_assert(git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
|
||||
cl_assert(git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_index_entries, 7));
|
||||
|
||||
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
|
||||
TEST_REPO_PATH "/.git/MERGE_MSG"));
|
||||
cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
|
||||
"Change all files\n" \
|
||||
"\n" \
|
||||
"Conflicts:\n" \
|
||||
"\tfile2.txt\n" \
|
||||
"\tfile3.txt\n") == 0);
|
||||
|
||||
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
|
||||
TEST_REPO_PATH "/file2.txt"));
|
||||
|
||||
cl_assert(strcmp(git_buf_cstr(&conflicting_buf),
|
||||
"!File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2!!\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"File 2\n" \
|
||||
"<<<<<<< HEAD\n" \
|
||||
"File 2\n" \
|
||||
"=======\n" \
|
||||
"File 2!\n" \
|
||||
"File 2\n" \
|
||||
"File 2!\n" \
|
||||
">>>>>>> e9b63f3... Change all files\n") == 0);
|
||||
|
||||
cl_git_pass(git_futils_readbuffer(&conflicting_buf,
|
||||
TEST_REPO_PATH "/file3.txt"));
|
||||
|
||||
cl_assert(strcmp(git_buf_cstr(&conflicting_buf),
|
||||
"!File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3!!\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"File 3\n" \
|
||||
"<<<<<<< HEAD\n" \
|
||||
"=======\n" \
|
||||
"File 3!\n" \
|
||||
"File 3!\n" \
|
||||
">>>>>>> e9b63f3... Change all files\n") == 0);
|
||||
|
||||
git_commit_free(commit);
|
||||
git_commit_free(head);
|
||||
git_buf_free(&mergemsg_buf);
|
||||
git_buf_free(&conflicting_buf);
|
||||
}
|
||||
|
||||
/* git reset --hard bafbf6912c09505ac60575cd43d3f2aba3bd84d8
|
||||
* git cherry-pick -X ours e9b63f3655b2ad80c0ff587389b5a9589a3a7110
|
||||
*/
|
||||
void test_cherrypick_workdir__conflict_use_ours(void)
|
||||
{
|
||||
git_commit *head = NULL, *commit = NULL;
|
||||
git_oid head_oid, cherry_oid;
|
||||
git_cherry_pick_options opts = GIT_CHERRY_PICK_OPTIONS_INIT;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
|
||||
{ 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 1, "file2.txt" },
|
||||
{ 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 2, "file2.txt" },
|
||||
{ 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 3, "file2.txt" },
|
||||
{ 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 1, "file3.txt" },
|
||||
{ 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 2, "file3.txt" },
|
||||
{ 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt" },
|
||||
};
|
||||
|
||||
struct merge_index_entry merge_filesystem_entries[] = {
|
||||
{ 0100644, "242e7977ba73637822ffb265b46004b9b0e5153b", 0, "file1.txt" },
|
||||
{ 0100644, "bd6ffc8c6c41f0f85ff9e3d61c9479516bac0024", 0, "file2.txt" },
|
||||
{ 0100644, "1124c2c1ae07b26fded662d6c3f3631d9dc16f88", 0, "file3.txt" },
|
||||
};
|
||||
|
||||
/* leave the index in a conflicted state, but checkout "ours" to the workdir */
|
||||
opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
|
||||
|
||||
git_oid_fromstr(&head_oid, "bafbf6912c09505ac60575cd43d3f2aba3bd84d8");
|
||||
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "e9b63f3655b2ad80c0ff587389b5a9589a3a7110");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
cl_git_pass(git_cherry_pick(repo, commit, &opts));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_index_entries, 7));
|
||||
cl_assert(merge_test_workdir(repo, merge_filesystem_entries, 3));
|
||||
|
||||
/* resolve conflicts in the index by taking "ours" */
|
||||
opts.merge_opts.file_favor = GIT_MERGE_FILE_FAVOR_OURS;
|
||||
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
cl_git_pass(git_cherry_pick(repo, commit, &opts));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_filesystem_entries, 3));
|
||||
cl_assert(merge_test_workdir(repo, merge_filesystem_entries, 3));
|
||||
|
||||
git_commit_free(commit);
|
||||
git_commit_free(head);
|
||||
}
|
||||
|
||||
/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
|
||||
* git cherry-pick 2a26c7e88b285613b302ba76712bc998863f3cbc
|
||||
*/
|
||||
void test_cherrypick_workdir__rename(void)
|
||||
{
|
||||
git_commit *head, *commit;
|
||||
git_oid head_oid, cherry_oid;
|
||||
git_cherry_pick_options opts = GIT_CHERRY_PICK_OPTIONS_INIT;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "19c5c7207054604b69c84d08a7571ef9672bb5c2", 0, "file1.txt" },
|
||||
{ 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 0, "file2.txt" },
|
||||
{ 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 0, "file3.txt.renamed" },
|
||||
};
|
||||
|
||||
opts.merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
|
||||
opts.merge_opts.rename_threshold = 50;
|
||||
|
||||
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
cl_git_pass(git_cherry_pick(repo, commit, &opts));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
|
||||
|
||||
git_commit_free(commit);
|
||||
git_commit_free(head);
|
||||
}
|
||||
|
||||
/* git reset --hard 44cd2ed2052c9c68f9a439d208e9614dc2a55c70
|
||||
* git cherry-pick 2a26c7e88b285613b302ba76712bc998863f3cbc
|
||||
*/
|
||||
void test_cherrypick_workdir__both_renamed(void)
|
||||
{
|
||||
git_commit *head, *commit;
|
||||
git_oid head_oid, cherry_oid;
|
||||
git_buf mergemsg_buf = GIT_BUF_INIT;
|
||||
git_cherry_pick_options opts = GIT_CHERRY_PICK_OPTIONS_INIT;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "19c5c7207054604b69c84d08a7571ef9672bb5c2", 0, "file1.txt" },
|
||||
{ 0100644, "a58ca3fee5eb68b11adc2703e5843f968c9dad1e", 0, "file2.txt" },
|
||||
{ 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 1, "file3.txt" },
|
||||
{ 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 3, "file3.txt.renamed" },
|
||||
{ 0100644, "28d9eb4208074ad1cc84e71ccc908b34573f05d2", 2, "file3.txt.renamed_on_branch" },
|
||||
};
|
||||
|
||||
opts.merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
|
||||
opts.merge_opts.rename_threshold = 50;
|
||||
|
||||
git_oid_fromstr(&head_oid, "44cd2ed2052c9c68f9a439d208e9614dc2a55c70");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "2a26c7e88b285613b302ba76712bc998863f3cbc");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
cl_git_pass(git_cherry_pick(repo, commit, &opts));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_index_entries, 5));
|
||||
|
||||
cl_git_pass(git_futils_readbuffer(&mergemsg_buf,
|
||||
TEST_REPO_PATH "/.git/MERGE_MSG"));
|
||||
cl_assert(strcmp(git_buf_cstr(&mergemsg_buf),
|
||||
"Renamed file3.txt -> file3.txt.renamed\n" \
|
||||
"\n" \
|
||||
"Conflicts:\n" \
|
||||
"\tfile3.txt\n" \
|
||||
"\tfile3.txt.renamed\n" \
|
||||
"\tfile3.txt.renamed_on_branch\n") == 0);
|
||||
|
||||
git_buf_free(&mergemsg_buf);
|
||||
git_commit_free(commit);
|
||||
git_commit_free(head);
|
||||
}
|
||||
|
||||
void test_cherrypick_workdir__nonmerge_fails_mainline_specified(void)
|
||||
{
|
||||
git_reference *head;
|
||||
git_commit *commit;
|
||||
git_cherry_pick_options opts = GIT_CHERRY_PICK_OPTIONS_INIT;
|
||||
|
||||
cl_git_pass(git_repository_head(&head, repo));
|
||||
cl_git_pass(git_reference_peel((git_object **)&commit, head, GIT_OBJ_COMMIT));
|
||||
|
||||
opts.mainline = 1;
|
||||
cl_must_fail(git_cherry_pick(repo, commit, &opts));
|
||||
cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
|
||||
cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
|
||||
|
||||
git_reference_free(head);
|
||||
git_commit_free(commit);
|
||||
}
|
||||
|
||||
/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
|
||||
* git cherry-pick abe4603bc7cd5b8167a267e0e2418fd2348f8cff
|
||||
*/
|
||||
void test_cherrypick_workdir__merge_fails_without_mainline_specified(void)
|
||||
{
|
||||
git_commit *head, *commit;
|
||||
git_oid head_oid, cherry_oid;
|
||||
|
||||
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
|
||||
cl_must_fail(git_cherry_pick(repo, commit, NULL));
|
||||
cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/CHERRY_PICK_HEAD"));
|
||||
cl_assert(!git_path_exists(TEST_REPO_PATH "/.git/MERGE_MSG"));
|
||||
|
||||
git_commit_free(commit);
|
||||
git_commit_free(head);
|
||||
}
|
||||
|
||||
/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
|
||||
* git cherry-pick -m1 abe4603bc7cd5b8167a267e0e2418fd2348f8cff
|
||||
*/
|
||||
void test_cherrypick_workdir__merge_first_parent(void)
|
||||
{
|
||||
git_commit *head, *commit;
|
||||
git_oid head_oid, cherry_oid;
|
||||
git_cherry_pick_options opts = GIT_CHERRY_PICK_OPTIONS_INIT;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "f90f9dcbdac2cce5cc166346160e19cb693ef4e8", 0, "file1.txt" },
|
||||
{ 0100644, "563f6473a3858f99b80e5f93c660512ed38e1e6f", 0, "file2.txt" },
|
||||
{ 0100644, "e233b9ed408a95e9d4b65fec7fc34943a556deb2", 0, "file3.txt" },
|
||||
};
|
||||
|
||||
opts.mainline = 1;
|
||||
|
||||
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
|
||||
cl_git_pass(git_cherry_pick(repo, commit, &opts));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
|
||||
|
||||
git_commit_free(commit);
|
||||
git_commit_free(head);
|
||||
}
|
||||
|
||||
/* git reset --hard cfc4f0999a8367568e049af4f72e452d40828a15
|
||||
* git cherry-pick -m2 abe4603bc7cd5b8167a267e0e2418fd2348f8cff
|
||||
*/
|
||||
void test_cherrypick_workdir__merge_second_parent(void)
|
||||
{
|
||||
git_commit *head, *commit;
|
||||
git_oid head_oid, cherry_oid;
|
||||
git_cherry_pick_options opts = GIT_CHERRY_PICK_OPTIONS_INIT;
|
||||
|
||||
struct merge_index_entry merge_index_entries[] = {
|
||||
{ 0100644, "487434cace79238a7091e2220611d4f20a765690", 0, "file1.txt" },
|
||||
{ 0100644, "e5183bfd18e3a0a691fadde2f0d5610b73282d31", 0, "file2.txt" },
|
||||
{ 0100644, "409a1bec58bf35348e8b62b72bb9c1f45cf5a587", 0, "file3.txt" },
|
||||
};
|
||||
|
||||
opts.mainline = 2;
|
||||
|
||||
git_oid_fromstr(&head_oid, "cfc4f0999a8367568e049af4f72e452d40828a15");
|
||||
cl_git_pass(git_commit_lookup(&head, repo, &head_oid));
|
||||
cl_git_pass(git_reset(repo, (git_object *)head, GIT_RESET_HARD, NULL, NULL));
|
||||
|
||||
git_oid_fromstr(&cherry_oid, "abe4603bc7cd5b8167a267e0e2418fd2348f8cff");
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &cherry_oid));
|
||||
|
||||
cl_git_pass(git_cherry_pick(repo, commit, &opts));
|
||||
|
||||
cl_assert(merge_test_index(repo_index, merge_index_entries, 3));
|
||||
|
||||
git_commit_free(commit);
|
||||
git_commit_free(head);
|
||||
}
|
||||
|
||||
1
tests/resources/cherrypick/.gitted/HEAD
Normal file
1
tests/resources/cherrypick/.gitted/HEAD
Normal file
@@ -0,0 +1 @@
|
||||
ref: refs/heads/automerge-branch
|
||||
7
tests/resources/cherrypick/.gitted/config
Normal file
7
tests/resources/cherrypick/.gitted/config
Normal file
@@ -0,0 +1,7 @@
|
||||
[core]
|
||||
repositoryformatversion = 0
|
||||
filemode = true
|
||||
bare = false
|
||||
logallrefupdates = true
|
||||
ignorecase = true
|
||||
precomposeunicode = true
|
||||
BIN
tests/resources/cherrypick/.gitted/index
Normal file
BIN
tests/resources/cherrypick/.gitted/index
Normal file
Binary file not shown.
6
tests/resources/cherrypick/.gitted/info/exclude
Normal file
6
tests/resources/cherrypick/.gitted/info/exclude
Normal file
@@ -0,0 +1,6 @@
|
||||
# git ls-files --others --exclude-from=.git/info/exclude
|
||||
# Lines that start with '#' are comments.
|
||||
# For a project mostly in C, the following would be a good set of
|
||||
# exclude patterns (uncomment them if you want to use them):
|
||||
# *.[oa]
|
||||
# *~
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,3 @@
|
||||
xĄÎA
|
||||
Â0@Q×9Ĺ왤“i"î—Ţ`L§µB¬MÓ…··ŕÜľĹç§)籂#ŢŐ˘
|
||||
^ťCNťŘä™”Îb+<1C>%¸<>¬ŹŠ÷¨bŢRôU!ő‰zŚ1Jh¸ő)JO}딼ë<08>b˝‘µ>¦WIóŞ\´äqy¬źŽĎź
祖QŞŇ”O`›ČDÍ6{t<>fÓmµę_sÓy‹‚@Ö2¨ů("O-
|
||||
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.
@@ -0,0 +1 @@
|
||||
x¥<>MjΓ0…»Φ)f_jτο„<>]΅Λά`$<24>—*Nδ1΄·―C=@—ο{πρ^YZ›lLO<4C>™Α”‚<E2809D>³―Uz‡ub“<62>·£/±βX1™μ"iu£ΞWN9ΊκbΩ<>„ΊθZ<03>S”&r4£mrY:ΌQΉoΌΒ+χ6―—ν{…ΓΗ/{?<>gΚ<><CE9A>`\<5C>ήk-<k«µΪι>Uψ_uζ+5<> Ξ<C2A0>μωx9ώ…a?υ¨Υ7<>W…
|
||||
@@ -0,0 +1 @@
|
||||
x•<>ÁJÅ0E]ç+f÷¢¤“Išw‚àGLÒÉk…´š¦ÿÞÊóÜž‡{óVëÒG{×›*¤ˆA9¹ ˆÊÄšcô:ÊPÜ”ˆCJ’Bž¬ù”¦k‡\2ËÌ]}ˆj‰¥PQÉãD6b”Á9ú¼5x“üuè¯Úê²ÏÇ÷O7v}Ù{[¤ËcÞê3Ž‘‹žàÞ¢µæ¤çÔ®ÿ<C2AE>#þEÌ»¶ëy³Éšg¸TÙÏà–µoPÕÃM™Í/X˜
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
x<01><>MjÃ0…»Ö)fj¤ñH– „ì]æÃdÔ¸Dq#ËÐÞ¾
|
||||
-tßåûáã=YJ™`HOª‚t.DòS´ä½JN.ø1ŠÁIÉ#góÁUo
$e›Râ8†É‡¨–gÊj/žÉFŒì¼á]–
|
||||
¯,÷MW8j-ózÙ¾VxyÿñÞk«37d){pc
|
||||
Ôˆ°³hénŸÚô
|
||||
îbNzã¢gÈóUÇ¡}6xÞÿ‰¡ŸzÄæï*V8
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
xĄŹÁNÄ0C9ç+推’É$M$´â†Ä‘XÍ&Úi!M%ř{şđ ÜěgɲÓZëÜÇp×› .É0Ą<30>c$Ť¦<C5A4>ÍÖňetBčPpLě˝Éę<C389>›,RITtŚ‘<C59A>őŁóA4E.TFr<>Ilśâ˝Ok<4F>Nź»lđ,ÎŰ´ođxýcoO[o3wŇZO`lôD.÷µV=¦vůW‰z•…«d(ó»Řˇux8ýš›ŽO·ôĽ.çKă%MęÖ?ZŘ
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
x<01><>MjÃ0…»Ö)fj¤ñH– „ì]æÃdÔ¸Dq#ËÐÞ¾
|
||||
-tßåûáã=YJ™`HOª‚t.DòS´ä½JN.ø1ŠÁIÉ#góÁUo
$e›Râ8†É‡¨–gÊj/žÉFŒì¼á]–
|
||||
¯,÷MW8j-ózÙ¾VxyÿñÞk«37d){pc
|
||||
Ôˆ°³hénŸÚô?J¿sÒ=Cž¯:í³ÁóþOýÔ#6ßïäV<
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
x+)JMU044d040031QHËÌI5Ô+©(aøô¦§çãÊßUÜE9sì‘ \uI‘X‘œÌvKYÕ;7níêøøMý3Kd“F’"c°¢ˆ•áï®x?3¦5ö×–¯·zÓÄѨ1*
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
x¥־=jֳ@@בװ{<7B>י
fvצLpgp“3ּ<33>F–²<>ױ×נםmנׂ¾גדֹ÷,sע«7Uאל$<24> ©₪<C2A9>1:HנEcָ.d*1<>Q«p5nzןא‚T²h}A"I.•<>SֵAֵ:‘Hysן}Z\Yv<E2808F>א¢m™·inpת´<E2808E>yכmז־GY—o°®ִ`ֹ$Dף®ןױ®<D7B1>BּO{L|‡f^הנOA
|
||||
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.
@@ -0,0 +1 @@
|
||||
x¥ÎMjÃ0†á®uŠÙÂHŠþ ”B<17>Üb4Ç.‘ÝJ2´·<C2B4> Gèöáãåã½”µƒqñ¥WÈ9<>¼ãl=#»`5GÎsDD5ê(ꋪlìXš!—„Æp°!e$2NÂÚ2{ç9†IÑÑ—½Â<C2BD>øû<C3B8>W©emËñÛàõóÏîïו:<3A>y/o mò“‚7pBƒ¨†Ž«]þQmw™`^¢Ïý§Ã¾A¡6ºê mT
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
x¥Î1ŠÃ0@ÑuŠéA<1E>¤,!] åÞ`,<2C>/h<>Èr‘ÛǰGHûŠÏÏKs¤ðÕ›*heæ”Éæ§8ªÅè<19>ýèJ*(&ó<>¦rÉTlJIØ…è«¥$…JD%<25>YF–ÁÙú}ip•üÜt…‹¶:¯÷íµÂ÷ï¿ÝÎko³t9楞`p)9ö5»î«]?Š˜}nsS¨ÚnjÞGPOL
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,4 @@
|
||||
x¥<>KNÄ0DYç½›Ùî´?Bì<42><C3AC>8D»ÓžÉHNÀqÜžŒFœ€í«ª'•¬µÎÐÆ‡ÞT!‰`*Â<±+,YÑZ
|
||||
%LÞˆóÆÙ„ýðÅM—ì“–X$çÄNÈ$S.cq89
|
||||
š‰ìDÞš¿¾¦ìo{¢ìxŠFL)Æ”‰ÅÄÈÁ}ÞûemðÁò½ëïÚê¼]öŸ
^®wv~Ûz›¹ó³¬õ,&?Ži„GãŒz\ëú/Éð©í¬<C3AD>/r<>Såíž`^ú
|
||||
õ=Ý£áX¾fZ
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
x¥ÍA
|
||||
B!€áÖžböAŒ6ŠBD» [¨o^Ï@$ݾ¡í·øÿÜj-Ú›ƒtf ä<C2A0>]²#““ã":dKiõ‹Æû51S@RqÊÖ:<b~Opç^ËØægÀåõ³çmH/Qâ)·z}ÎjCˆpDƒ¨vÝ×ÂEÔK»<È
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
x¥ÎÍJÅ0@a×yŠì…Ëä?] ¾Åd2i+7<>¦)èÛ[ðÜ~‹Ã¡ÞÚ6¥öîafY<66><59>–’ÏÕH1„ì¼K%¢+E<17>!…(>qð>¥q”µehMÁ„”}ÈP˜”!ò:ÖCxεùŽôuò!ßx´íXÏŸC>}üÙòṟáÄõö,•IÞç‚“<E2809A> Ä¥×êäEÄë9{ã±0æ;KZq_®<5F>¾ËºÝYÝæ÷¿t3V<33>
|
||||
Binary file not shown.
@@ -0,0 +1 @@
|
||||
xĄŽAjĂ0E»Ö)f_¶¤‘,ˇ]z‹‘<˛]"«•ÇĐŢľ‚!Ë˙ř<^ŞĄlÚá‹4fŔě=iM0HÉir: š<kiFGž§hI}Să] ő™ă4FÇ ŤťqfĘšl˙Äŕ’ÁŹŻč”µ6ř¤ôsňÜĘv¬çßׯ[Ţi ]R-7č ÎÄ áuĐĂ :í©ÂOIÔű)µp[<5B>âť!´/=§î<C2A7>·;ë‹üŠú&éWY
|
||||
@@ -0,0 +1 @@
|
||||
x¥ÎKJ1€a×9Eí…!ïI@df%x‹ª¤ú!“ަ«AooƒGpû-~þÒ[[lO2˜AW﯋
6‘ŽÑÄRÙ‘Õ=yFW¥ƒúÄÁ›@Õ“5l®Ä(×™šœÏÚçdúÉr†²ôïX¾Þá<C39E>G[÷åøÙáåãÏæÛ.cEÁKéíŒËÑ»²…gmµV§ž«ÂÿЍû!½ñ˜éÁPÜæs§o0vùõ*Wd
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,2 @@
|
||||
x¥ÎMjÃ0@á®uŠÙŠ<Ë!<21>E¡·É£ØÅ?‰$/rûz„n¿Åã¥}]çHÃG+ªzåè¼"*k
|
||||
¡×AºìÆHìc”èÓhÍ]Šn
RN”-3Kp~è}PK,™ò€J=Ždéz#G›ö?’‡VøÖ²Îu:žN¿v»ÔVfiò•öõ<0C>cOÎ;‹ðiÑZóÖ÷jÓEÌu’í¦ Ëy^´š-˜P@
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
d3d77487660ee3c0194ee01dc5eaf478782b1c7e
|
||||
1
tests/resources/cherrypick/.gitted/refs/heads/master
Normal file
1
tests/resources/cherrypick/.gitted/refs/heads/master
Normal file
@@ -0,0 +1 @@
|
||||
2a26c7e88b285613b302ba76712bc998863f3cbc
|
||||
@@ -0,0 +1 @@
|
||||
abe4603bc7cd5b8167a267e0e2418fd2348f8cff
|
||||
@@ -0,0 +1 @@
|
||||
bafbf6912c09505ac60575cd43d3f2aba3bd84d8
|
||||
@@ -0,0 +1 @@
|
||||
cfc4f0999a8367568e049af4f72e452d40828a15
|
||||
1
tests/resources/cherrypick/.gitted/refs/heads/orphan
Normal file
1
tests/resources/cherrypick/.gitted/refs/heads/orphan
Normal file
@@ -0,0 +1 @@
|
||||
74f06b5bfec6d33d7264f73606b57a7c0b963819
|
||||
1
tests/resources/cherrypick/.gitted/refs/heads/renames
Normal file
1
tests/resources/cherrypick/.gitted/refs/heads/renames
Normal file
@@ -0,0 +1 @@
|
||||
44cd2ed2052c9c68f9a439d208e9614dc2a55c70
|
||||
15
tests/resources/cherrypick/file1.txt
Normal file
15
tests/resources/cherrypick/file1.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
!File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
File 1
|
||||
15
tests/resources/cherrypick/file2.txt
Normal file
15
tests/resources/cherrypick/file2.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
!File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
File 2
|
||||
15
tests/resources/cherrypick/file3.txt
Normal file
15
tests/resources/cherrypick/file3.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
!File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
File 3
|
||||
Reference in New Issue
Block a user