|
2 | 2 | #include "patch.h"
|
3 | 3 | #include "patch_parse.h"
|
4 | 4 | #include "diff_helpers.h"
|
| 5 | +#include "../src/diff.h" |
5 | 6 |
|
6 | 7 | #include "../patch/patch_common.h"
|
7 | 8 |
|
@@ -151,3 +152,47 @@ void test_diff_parse__can_parse_generated_diff(void)
|
151 | 152 | GIT_DIFF_FIND_COPIES_FROM_UNMODIFIED | GIT_DIFF_FIND_EXACT_MATCH_ONLY);
|
152 | 153 | }
|
153 | 154 |
|
| 155 | +void test_diff_parse__get_patch_from_diff(void) |
| 156 | +{ |
| 157 | + git_repository *repo; |
| 158 | + git_diff *computed, *parsed; |
| 159 | + git_tree *a, *b; |
| 160 | + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; |
| 161 | + git_buf computed_buf = GIT_BUF_INIT; |
| 162 | + git_patch *patch_computed, *patch_parsed; |
| 163 | + |
| 164 | + repo = cl_git_sandbox_init("diff"); |
| 165 | + |
| 166 | + opts.flags = GIT_DIFF_SHOW_BINARY; |
| 167 | + |
| 168 | + cl_assert((a = resolve_commit_oid_to_tree(repo, |
| 169 | + "d70d245ed97ed2aa596dd1af6536e4bfdb047b69")) != NULL); |
| 170 | + cl_assert((b = resolve_commit_oid_to_tree(repo, |
| 171 | + "7a9e0b02e63179929fed24f0a3e0f19168114d10")) != NULL); |
| 172 | + |
| 173 | + cl_git_pass(git_diff_tree_to_tree(&computed, repo, a, b, &opts)); |
| 174 | + cl_git_pass(git_diff_to_buf(&computed_buf, |
| 175 | + computed, GIT_DIFF_FORMAT_PATCH)); |
| 176 | + cl_git_pass(git_patch_from_diff(&patch_computed, computed, 0)); |
| 177 | + |
| 178 | + cl_git_pass(git_diff_from_buffer(&parsed, |
| 179 | + computed_buf.ptr, computed_buf.size)); |
| 180 | + cl_git_pass(git_patch_from_diff(&patch_parsed, parsed, 0)); |
| 181 | + |
| 182 | + cl_assert_equal_i( |
| 183 | + git_patch_num_hunks(patch_computed), |
| 184 | + git_patch_num_hunks(patch_parsed)); |
| 185 | + |
| 186 | + git_patch_free(patch_computed); |
| 187 | + git_patch_free(patch_parsed); |
| 188 | + |
| 189 | + git_tree_free(a); |
| 190 | + git_tree_free(b); |
| 191 | + |
| 192 | + git_diff_free(computed); |
| 193 | + git_diff_free(parsed); |
| 194 | + |
| 195 | + git_buf_free(&computed_buf); |
| 196 | + |
| 197 | + cl_git_sandbox_cleanup(); |
| 198 | +} |
0 commit comments