diff options
Diffstat (limited to 'tests/diff/blob.c')
-rw-r--r-- | tests/diff/blob.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/tests/diff/blob.c b/tests/diff/blob.c index c3933c313..05cc28218 100644 --- a/tests/diff/blob.c +++ b/tests/diff/blob.c @@ -1,6 +1,19 @@ #include "clar_libgit2.h" #include "diff_helpers.h" +#define BLOB_DIFF \ + "diff --git a/file b/file\n" \ + "index 45141a7..4d713dc 100644\n" \ + "--- a/file\n" \ + "+++ b/file\n" \ + "@@ -1 +1,6 @@\n" \ + " Hello from the root\n" \ + "+\n" \ + "+Some additional lines\n" \ + "+\n" \ + "+Down here below\n" \ + "+\n" + static git_repository *g_repo = NULL; static diff_expects expected; static git_diff_options opts; @@ -65,6 +78,32 @@ static void assert_one_modified( cl_assert_equal_i(dels, exp->line_dels); } +void test_diff_blob__patch_with_freed_blobs(void) +{ + git_oid a_oid, b_oid; + git_blob *a, *b; + git_patch *p; + git_buf buf = GIT_BUF_INIT; + + /* tests/resources/attr/root_test1 */ + cl_git_pass(git_oid_fromstrn(&a_oid, "45141a79", 8)); + cl_git_pass(git_blob_lookup_prefix(&a, g_repo, &a_oid, 4)); + /* tests/resources/attr/root_test2 */ + cl_git_pass(git_oid_fromstrn(&b_oid, "4d713dc4", 8)); + cl_git_pass(git_blob_lookup_prefix(&b, g_repo, &b_oid, 4)); + + cl_git_pass(git_patch_from_blobs(&p, a, NULL, b, NULL, NULL)); + + git_blob_free(a); + git_blob_free(b); + + cl_git_pass(git_patch_to_buf(&buf, p)); + cl_assert_equal_s(buf.ptr, BLOB_DIFF); + + git_patch_free(p); + git_buf_free(&buf); +} + void test_diff_blob__can_compare_text_blobs(void) { git_blob *a, *b, *c; |