|
1 | 1 | #include "clar_libgit2.h" |
2 | 2 | #include "patch.h" |
3 | 3 | #include "patch_parse.h" |
| 4 | +#include "diff_helpers.h" |
4 | 5 |
|
5 | 6 | #include "../patch/patch_common.h" |
6 | 7 |
|
| 8 | +void test_diff_parse__cleanup(void) |
| 9 | +{ |
| 10 | + cl_git_sandbox_cleanup(); |
| 11 | +} |
| 12 | + |
7 | 13 | void test_diff_parse__nonpatches_fail_with_notfound(void) |
8 | 14 | { |
9 | 15 | git_diff *diff; |
@@ -58,3 +64,65 @@ void test_diff_parse__invalid_patches_fails(void) |
58 | 64 | test_parse_invalid_diff(PATCH_CORRUPT_MISSING_HUNK_HEADER); |
59 | 65 | } |
60 | 66 |
|
| 67 | +static void test_tree_to_tree_computed_to_parsed( |
| 68 | + const char *sandbox, const char *a_id, const char *b_id) |
| 69 | +{ |
| 70 | + git_repository *repo; |
| 71 | + git_diff *computed, *parsed; |
| 72 | + git_tree *a, *b; |
| 73 | + git_diff_options opts = GIT_DIFF_OPTIONS_INIT; |
| 74 | + git_diff_find_options findopts = GIT_DIFF_FIND_OPTIONS_INIT; |
| 75 | + git_buf computed_buf = GIT_BUF_INIT; |
| 76 | + |
| 77 | + repo = cl_git_sandbox_init(sandbox); |
| 78 | + |
| 79 | + opts.id_abbrev = GIT_OID_HEXSZ; |
| 80 | + opts.flags = GIT_DIFF_SHOW_BINARY; |
| 81 | + |
| 82 | + cl_assert((a = resolve_commit_oid_to_tree(repo, a_id)) != NULL); |
| 83 | + cl_assert((b = resolve_commit_oid_to_tree(repo, b_id)) != NULL); |
| 84 | + |
| 85 | + cl_git_pass(git_diff_tree_to_tree(&computed, repo, a, b, &opts)); |
| 86 | + cl_git_pass(git_diff_to_buf(&computed_buf, |
| 87 | + computed, GIT_DIFF_FORMAT_PATCH)); |
| 88 | + |
| 89 | + cl_git_pass(git_diff_from_buffer(&parsed, |
| 90 | + computed_buf.ptr, computed_buf.size)); |
| 91 | + |
| 92 | + diff_assert_equal(computed, parsed); |
| 93 | + |
| 94 | + git_tree_free(a); |
| 95 | + git_tree_free(b); |
| 96 | + |
| 97 | + git_diff_free(computed); |
| 98 | + git_diff_free(parsed); |
| 99 | + |
| 100 | + git_buf_free(&computed_buf); |
| 101 | + |
| 102 | + cl_git_sandbox_cleanup(); |
| 103 | +} |
| 104 | + |
| 105 | +void test_diff_parse__can_parse_generated_diff(void) |
| 106 | +{ |
| 107 | + test_tree_to_tree_computed_to_parsed("diff", "d70d245e", "7a9e0b02"); |
| 108 | + test_tree_to_tree_computed_to_parsed( |
| 109 | + "unsymlinked.git", "806999", "a8595c"); |
| 110 | + test_tree_to_tree_computed_to_parsed("diff", |
| 111 | + "d70d245ed97ed2aa596dd1af6536e4bfdb047b69", |
| 112 | + "7a9e0b02e63179929fed24f0a3e0f19168114d10"); |
| 113 | + test_tree_to_tree_computed_to_parsed( |
| 114 | + "unsymlinked.git", "7fccd7", "806999"); |
| 115 | + test_tree_to_tree_computed_to_parsed( |
| 116 | + "unsymlinked.git", "7fccd7", "a8595c"); |
| 117 | + test_tree_to_tree_computed_to_parsed("attr", "605812a", "370fe9ec22"); |
| 118 | + test_tree_to_tree_computed_to_parsed( |
| 119 | + "attr", "f5b0af1fb4f5c", "370fe9ec22"); |
| 120 | + test_tree_to_tree_computed_to_parsed("diff", "d70d245e", "d70d245e"); |
| 121 | + test_tree_to_tree_computed_to_parsed("diff_format_email", |
| 122 | + "873806f6f27e631eb0b23e4b56bea2bfac14a373", |
| 123 | + "897d3af16ca9e420cd071b1c4541bd2b91d04c8c"); |
| 124 | + test_tree_to_tree_computed_to_parsed("diff_format_email", |
| 125 | + "897d3af16ca9e420cd071b1c4541bd2b91d04c8c", |
| 126 | + "873806f6f27e631eb0b23e4b56bea2bfac14a373"); |
| 127 | +} |
| 128 | + |
0 commit comments