Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2013-08-01 06:51:50 +0400
committerRussell Belfer <rb@github.com>2013-08-05 00:44:51 +0400
commita42c2a8c89189afbcfccbc17f798971c18c15de6 (patch)
tree2ab1c3b01e76220e39e52b286cae8c4e6a6584c2 /tests-clar/diff
parentd730d3f4f0efb269dd760a3100ae86c460b8ba36 (diff)
Rename test for multiple similar matches
A rename test that illustrates a source matching multiple targets.
Diffstat (limited to 'tests-clar/diff')
-rw-r--r--tests-clar/diff/rename.c66
1 files changed, 63 insertions, 3 deletions
diff --git a/tests-clar/diff/rename.c b/tests-clar/diff/rename.c
index 20ee66288..108b34621 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;