summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@github.com>2022-02-11 11:02:00 -0500
committerEdward Thomson <ethomson@github.com>2022-02-11 17:56:28 -0500
commite49e5f2fb51c2fcc4ee09b5fa90999582a7a6468 (patch)
tree67f5c852dd5f991067e6a8c19549d8985da4716f
parent90a6637492a6e6ebf0698baeb1f648aeda0f5107 (diff)
downloadlibgit2-e49e5f2fb51c2fcc4ee09b5fa90999582a7a6468.tar.gz
diff_file: test empty workdir file grows after obtaining a diff
This test was also provided by @jorio https://github.com/libgit2/libgit2/pull/6208#issuecomment-1034072050
-rw-r--r--tests/diff/externalmodifications.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/tests/diff/externalmodifications.c b/tests/diff/externalmodifications.c
index 09687c51e..df62c3316 100644
--- a/tests/diff/externalmodifications.c
+++ b/tests/diff/externalmodifications.c
@@ -96,7 +96,7 @@ void test_diff_externalmodifications__file_deleted(void)
/* Delete the file */
cl_git_rmfile(path.ptr);
-
+
/* Attempt to get a patch */
cl_git_fail(git_patch_from_diff(&patch, diff, 0));
@@ -104,3 +104,30 @@ void test_diff_externalmodifications__file_deleted(void)
git_diff_free(diff);
git_str_dispose(&path);
}
+
+void test_diff_externalmodifications__empty_file_becomes_non_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"));
+
+ /* Empty out the file */
+ cl_git_mkfile(path.ptr, "");
+
+ /* 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(0, git_diff_get_delta(diff, 0)->new_file.size);
+
+ /* Simulate file modification after we've gotten the diff */
+ cl_git_mkfile(path.ptr, "hello");
+ cl_git_fail(git_patch_from_diff(&patch, diff, 0));
+
+ git_index_free(index);
+ git_diff_free(diff);
+ git_str_dispose(&path);
+}