Skip to content

Commit 9aade20

Browse files
jorioEdward Thomson
authored andcommitted
diff_file: test workdir file becomes empty after obtaining a diff
1 parent 3bac68f commit 9aade20

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

tests/diff/externalmodifications.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,35 @@ void test_diff_externalmodifications__file_becomes_smaller(void)
5151
git_str_dispose(&path);
5252
}
5353

54+
void test_diff_externalmodifications__file_becomes_empty(void)
55+
{
56+
git_index *index;
57+
git_diff *diff;
58+
git_patch* patch;
59+
git_str path = GIT_STR_INIT;
60+
61+
cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "README"));
62+
63+
/* Modify the file */
64+
cl_git_mkfile(path.ptr, "hello");
65+
66+
/* Get a diff */
67+
cl_git_pass(git_repository_index(&index, g_repo));
68+
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL));
69+
cl_assert_equal_i(1, git_diff_num_deltas(diff));
70+
cl_assert_equal_i(5, git_diff_get_delta(diff, 0)->new_file.size);
71+
72+
/* Empty out the file after we've gotten the diff */
73+
cl_git_mkfile(path.ptr, "");
74+
75+
/* Attempt to get a patch */
76+
cl_git_fail(git_patch_from_diff(&patch, diff, 0));
77+
78+
git_index_free(index);
79+
git_diff_free(diff);
80+
git_str_dispose(&path);
81+
}
82+
5483
void test_diff_externalmodifications__file_deleted(void)
5584
{
5685
git_index *index;

0 commit comments

Comments
 (0)