diff options
author | Patrick Steinhardt <ps@pks.im> | 2017-03-14 11:01:19 +0100 |
---|---|---|
committer | Patrick Steinhardt <ps@pks.im> | 2017-03-14 13:09:35 +0100 |
commit | c0eba379d18c6f7979d09c672b48feeaca69dfbd (patch) | |
tree | 120d2d4f442758cdff41dbe9ca7d6ba00125db58 /tests/diff/parse.c | |
parent | ad5a909cfbb07541e3e2548313043cc3f3a0918a (diff) | |
download | libgit2-c0eba379d18c6f7979d09c672b48feeaca69dfbd.tar.gz |
diff_parse: correctly set options for parsed diffs
The function `diff_parsed_alloc` allocates and initializes a
`git_diff_parsed` structure. This structure also contains diff options.
While we initialize its flags, we fail to do a real initialization of
its values. This bites us when we want to actually use the generated
diff as we do not se the option's version field, which is required to
operate correctly.
Fix the issue by executing `git_diff_init_options` on the embedded
struct.
Diffstat (limited to 'tests/diff/parse.c')
-rw-r--r-- | tests/diff/parse.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/diff/parse.c b/tests/diff/parse.c index 35870594a..acb6eb8a5 100644 --- a/tests/diff/parse.c +++ b/tests/diff/parse.c @@ -246,3 +246,24 @@ void test_diff_parse__parsing_minimal_patch_succeeds(void) git_diff_free(diff); git_buf_free(&buf); } + +void test_diff_parse__patch_roundtrip_succeeds(void) +{ + const char buf1[] = "a\n", buf2[] = "b\n"; + git_buf patchbuf = GIT_BUF_INIT, diffbuf = GIT_BUF_INIT; + git_patch *patch; + git_diff *diff; + + cl_git_pass(git_patch_from_buffers(&patch, buf1, strlen(buf1), "obj1", buf2, strlen(buf2), "obj2", NULL)); + cl_git_pass(git_patch_to_buf(&patchbuf, patch)); + + cl_git_pass(git_diff_from_buffer(&diff, patchbuf.ptr, patchbuf.size)); + cl_git_pass(git_diff_to_buf(&diffbuf, diff, GIT_DIFF_FORMAT_PATCH)); + + cl_assert_equal_s(patchbuf.ptr, diffbuf.ptr); + + git_patch_free(patch); + git_diff_free(diff); + git_buf_free(&patchbuf); + git_buf_free(&diffbuf); +} |