diff options
author | Edward Thomson <ethomson@github.com> | 2016-08-23 23:38:39 -0500 |
---|---|---|
committer | Edward Thomson <ethomson@github.com> | 2016-08-24 09:08:57 -0500 |
commit | b859faa61ce3f1fda5c29ac1e72a3d58fee2ede6 (patch) | |
tree | 976a27f8827db4200a172720b547fbf7ec1db119 /tests/diff/parse.c | |
parent | c60210d36780a39db669e52d6d592d339c6a2ed3 (diff) | |
download | libgit2-ethomson/patch_from_diff.tar.gz |
Teach `git_patch_from_diff` about parsed diffsethomson/patch_from_diff
Ensure that `git_patch_from_diff` can return the patch for parsed diffs,
not just generate a patch for a generated diff.
Diffstat (limited to 'tests/diff/parse.c')
-rw-r--r-- | tests/diff/parse.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/diff/parse.c b/tests/diff/parse.c index 83000a92d..a06813d1b 100644 --- a/tests/diff/parse.c +++ b/tests/diff/parse.c @@ -2,6 +2,7 @@ #include "patch.h" #include "patch_parse.h" #include "diff_helpers.h" +#include "../src/diff.h" #include "../patch/patch_common.h" @@ -151,3 +152,47 @@ void test_diff_parse__can_parse_generated_diff(void) GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED | GIT_DIFF_FIND_EXACT_MATCH_ONLY); } +void test_diff_parse__get_patch_from_diff(void) +{ + git_repository *repo; + git_diff *computed, *parsed; + git_tree *a, *b; + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; + git_buf computed_buf = GIT_BUF_INIT; + git_patch *patch_computed, *patch_parsed; + + repo = cl_git_sandbox_init("diff"); + + opts.flags = GIT_DIFF_SHOW_BINARY; + + cl_assert((a = resolve_commit_oid_to_tree(repo, + "d70d245ed97ed2aa596dd1af6536e4bfdb047b69")) != NULL); + cl_assert((b = resolve_commit_oid_to_tree(repo, + "7a9e0b02e63179929fed24f0a3e0f19168114d10")) != NULL); + + cl_git_pass(git_diff_tree_to_tree(&computed, repo, a, b, &opts)); + cl_git_pass(git_diff_to_buf(&computed_buf, + computed, GIT_DIFF_FORMAT_PATCH)); + cl_git_pass(git_patch_from_diff(&patch_computed, computed, 0)); + + cl_git_pass(git_diff_from_buffer(&parsed, + computed_buf.ptr, computed_buf.size)); + cl_git_pass(git_patch_from_diff(&patch_parsed, parsed, 0)); + + cl_assert_equal_i( + git_patch_num_hunks(patch_computed), + git_patch_num_hunks(patch_parsed)); + + git_patch_free(patch_computed); + git_patch_free(patch_parsed); + + git_tree_free(a); + git_tree_free(b); + + git_diff_free(computed); + git_diff_free(parsed); + + git_buf_free(&computed_buf); + + cl_git_sandbox_cleanup(); +} |