Commit 9aade20b by Iliyas Jorio Committed by Edward Thomson

diff_file: test workdir file becomes empty after obtaining a diff

parent 3bac68ff
...@@ -51,6 +51,35 @@ void test_diff_externalmodifications__file_becomes_smaller(void) ...@@ -51,6 +51,35 @@ void test_diff_externalmodifications__file_becomes_smaller(void)
git_str_dispose(&path); git_str_dispose(&path);
} }
void test_diff_externalmodifications__file_becomes_empty(void)
{
git_index *index;
git_diff *diff;
git_patch* patch;
git_str path = GIT_STR_INIT;
cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "README"));
/* Modify the file */
cl_git_mkfile(path.ptr, "hello");
/* Get a diff */
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL));
cl_assert_equal_i(1, git_diff_num_deltas(diff));
cl_assert_equal_i(5, git_diff_get_delta(diff, 0)->new_file.size);
/* Empty out the file after we've gotten the diff */
cl_git_mkfile(path.ptr, "");
/* Attempt to get a patch */
cl_git_fail(git_patch_from_diff(&patch, diff, 0));
git_index_free(index);
git_diff_free(diff);
git_str_dispose(&path);
}
void test_diff_externalmodifications__file_deleted(void) void test_diff_externalmodifications__file_deleted(void)
{ {
git_index *index; git_index *index;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment