Skip to content

Commit e1415dc

Browse files
author
Edward Thomson
committed
diff_file: test empty workdir file grows after obtaining a diff
This test was also provided by @jorio libgit2#6208 (comment)
1 parent 9aade20 commit e1415dc

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

tests/diff/externalmodifications.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,38 @@ void test_diff_externalmodifications__file_deleted(void)
9696

9797
/* Delete the file */
9898
cl_git_rmfile(path.ptr);
99-
99+
100100
/* Attempt to get a patch */
101101
cl_git_fail(git_patch_from_diff(&patch, diff, 0));
102102

103103
git_index_free(index);
104104
git_diff_free(diff);
105105
git_str_dispose(&path);
106106
}
107+
108+
void test_diff_externalmodifications__empty_file_becomes_non_empty(void)
109+
{
110+
git_index *index;
111+
git_diff *diff;
112+
git_patch* patch;
113+
git_str path = GIT_STR_INIT;
114+
115+
cl_git_pass(git_str_joinpath(&path, git_repository_workdir(g_repo), "README"));
116+
117+
/* Empty out the file */
118+
cl_git_mkfile(path.ptr, "");
119+
120+
/* Get a diff */
121+
cl_git_pass(git_repository_index(&index, g_repo));
122+
cl_git_pass(git_diff_index_to_workdir(&diff, g_repo, index, NULL));
123+
cl_assert_equal_i(1, git_diff_num_deltas(diff));
124+
cl_assert_equal_i(0, git_diff_get_delta(diff, 0)->new_file.size);
125+
126+
/* Simulate file modification after we've gotten the diff */
127+
cl_git_mkfile(path.ptr, "hello");
128+
cl_git_fail(git_patch_from_diff(&patch, diff, 0));
129+
130+
git_index_free(index);
131+
git_diff_free(diff);
132+
git_str_dispose(&path);
133+
}

0 commit comments

Comments
 (0)