Rename test for multiple similar matches A rename test that illustrates a source matching multiple targets.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index 20ee662..108b346 100644
--- a/tests-clar/diff/rename.c
+++ b/tests-clar/diff/rename.c
@@ -871,6 +871,8 @@ void test_diff_rename__from_deleted_to_split(void)
struct rename_expected
{
size_t len;
+
+ unsigned int *status;
const char **sources;
const char **targets;
@@ -885,7 +887,7 @@ int test_names_expected(const git_diff_delta *delta, float progress, void *p)
cl_assert(expected->idx < expected->len);
- cl_assert_equal_i(delta->status, GIT_DELTA_RENAMED);
+ cl_assert_equal_i(delta->status, expected->status[expected->idx]);
cl_assert(git__strcmp(expected->sources[expected->idx],
delta->old_file.path) == 0);
@@ -907,9 +909,10 @@ void test_diff_rename__rejected_match_can_match_others(void)
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
git_buf one = GIT_BUF_INIT, two = GIT_BUF_INIT;
+ unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
const char *sources[] = { "Class1.cs", "Class2.cs" };
const char *targets[] = { "ClassA.cs", "ClassB.cs" };
- struct rename_expected expect = { 2, sources, targets };
+ struct rename_expected expect = { 2, status, sources, targets };
char *ptr;
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
@@ -991,9 +994,10 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
git_diff_list *diff;
git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
+ unsigned int status[] = { GIT_DELTA_RENAMED, GIT_DELTA_RENAMED };
const char *sources[] = { "a.txt", "b.txt" };
const char *targets[] = { "c.txt", "d.txt" };
- struct rename_expected expect = { 2, sources, targets };
+ struct rename_expected expect = { 2, status, sources, targets };
opts.checkout_strategy = GIT_CHECKOUT_FORCE;
@@ -1036,6 +1040,62 @@ void test_diff_rename__rejected_match_can_match_others_two(void)
git_reference_free(selfsimilar);
}
+void test_diff_rename__rejected_match_can_match_others_three(void)
+{
+ git_reference *head, *selfsimilar;
+ git_index *index;
+ git_tree *tree;
+ git_checkout_opts opts = GIT_CHECKOUT_OPTS_INIT;
+ git_diff_list *diff;
+ git_diff_options diffopts = GIT_DIFF_OPTIONS_INIT;
+ git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT;
+
+ /* Both cannot be renames from a.txt */
+ unsigned int status[] = { GIT_DELTA_ADDED, GIT_DELTA_RENAMED };
+ const char *sources[] = { "0001.txt", "a.txt" };
+ const char *targets[] = { "0001.txt", "0002.txt" };
+ struct rename_expected expect = { 2, status, sources, targets };
+
+ opts.checkout_strategy = GIT_CHECKOUT_FORCE;
+
+ cl_git_pass(git_reference_lookup(&head, g_repo, "HEAD"));
+ cl_git_pass(git_reference_symbolic_set_target(
+ &selfsimilar, head, "refs/heads/renames_similar_two"));
+ cl_git_pass(git_checkout_head(g_repo, &opts));
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ cl_git_pass(p_unlink("renames/a.txt"));
+
+ cl_git_pass(git_index_remove_bypath(index, "a.txt"));
+
+ write_similarity_file_two("renames/0001.txt", 7);
+ write_similarity_file_two("renames/0002.txt", 0);
+
+ cl_git_pass(git_index_add_bypath(index, "0001.txt"));
+ cl_git_pass(git_index_add_bypath(index, "0002.txt"));
+
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(
+ git_revparse_single((git_object **)&tree, g_repo, "HEAD^{tree}"));
+
+ cl_git_pass(
+ git_diff_tree_to_index(&diff, g_repo, tree, index, &diffopts));
+
+ cl_git_pass(git_diff_find_similar(diff, &findopts));
+
+ cl_git_pass(
+ git_diff_foreach(diff, test_names_expected, NULL, NULL, &expect));
+
+ cl_assert(expect.idx == expect.len);
+
+ git_diff_list_free(diff);
+ git_tree_free(tree);
+ git_index_free(index);
+ git_reference_free(head);
+ git_reference_free(selfsimilar);
+}
+
void test_diff_rename__case_changes_are_split(void)
{
git_index *index;