diff conflicts: test index to workdir w/ conflicts
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
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 963be94..460f1b5 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -68,6 +68,51 @@ void test_diff_workdir__to_index(void)
git_diff_free(diff);
}
+void test_diff_workdir__to_index_with_conflicts(void)
+{
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
+ git_diff *diff = NULL;
+ git_index *index;
+ git_index_entry our_entry = {0}, their_entry = {0};
+ diff_expects exp = {0};
+
+ g_repo = cl_git_sandbox_init("status");
+
+ opts.context_lines = 3;
+ opts.interhunk_lines = 1;
+
+ /* Adding an entry that represents a rename gets two files in conflict */
+ our_entry.path = "subdir/modified_file";
+ our_entry.mode = 0100644;
+
+ their_entry.path = "subdir/rename_conflict";
+ their_entry.mode = 0100644;
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_conflict_add(index, NULL, &our_entry, &their_entry));
+
+ cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, &opts));
+
+ cl_git_pass(diff_foreach_via_iterator(
+ diff, diff_file_cb, diff_hunk_cb, diff_line_cb, &exp));
+
+ cl_assert_equal_i(9, exp.files);
+ cl_assert_equal_i(0, exp.file_status[GIT_DELTA_ADDED]);
+ cl_assert_equal_i(4, exp.file_status[GIT_DELTA_DELETED]);
+ cl_assert_equal_i(3, exp.file_status[GIT_DELTA_MODIFIED]);
+ cl_assert_equal_i(2, exp.file_status[GIT_DELTA_CONFLICTED]);
+
+ cl_assert_equal_i(7, exp.hunks);
+
+ cl_assert_equal_i(12, exp.lines);
+ cl_assert_equal_i(4, exp.line_ctxt);
+ cl_assert_equal_i(3, exp.line_adds);
+ cl_assert_equal_i(5, exp.line_dels);
+
+ git_diff_free(diff);
+ git_index_free(index);
+}
+
void test_diff_workdir__to_index_with_assume_unchanged(void)
{
git_diff_options opts = GIT_DIFF_OPTIONS_INIT;