diff options
author | Russell Belfer <rb@github.com> | 2012-10-24 20:56:32 -0700 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2012-10-24 20:56:32 -0700 |
commit | 93cf7bb8e26a04d9bd4197c1b938cee352023f63 (patch) | |
tree | 34fc8c5fbf63e3962573d768c252197bcdf177e3 /tests-clar/diff/patch.c | |
parent | 6f6b0c013c6eff2aca2a7ada1027044f2e20f578 (diff) | |
download | libgit2-93cf7bb8e26a04d9bd4197c1b938cee352023f63.tar.gz |
Add git_diff_patch_to_str API
This adds an API to generate a complete single-file patch text
from a git_diff_patch object.
Diffstat (limited to 'tests-clar/diff/patch.c')
-rw-r--r-- | tests-clar/diff/patch.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests-clar/diff/patch.c b/tests-clar/diff/patch.c index e8468386c..dce6d6da2 100644 --- a/tests-clar/diff/patch.c +++ b/tests-clar/diff/patch.c @@ -97,3 +97,33 @@ void test_diff_patch__can_properly_display_the_removal_of_a_file(void) git_tree_free(another); git_tree_free(one); } + +void test_diff_patch__to_string(void) +{ + const char *one_sha = "26a125e"; + const char *another_sha = "735b6a2"; + git_tree *one, *another; + git_diff_list *diff; + git_diff_patch *patch; + char *text; + const char *expected = "diff --git a/subdir.txt b/subdir.txt\ndeleted file mode 100644\nindex e8ee89e..0000000\n--- a/subdir.txt\n+++ /dev/null\n@@ -1,2 +0,0 @@\n-Is it a bird?\n-Is it a plane?\n"; + + one = resolve_commit_oid_to_tree(g_repo, one_sha); + another = resolve_commit_oid_to_tree(g_repo, another_sha); + + cl_git_pass(git_diff_tree_to_tree(g_repo, NULL, one, another, &diff)); + + cl_assert_equal_i(1, git_diff_num_deltas(diff)); + + cl_git_pass(git_diff_get_patch(&patch, NULL, diff, 0)); + + cl_git_pass(git_diff_patch_to_str(&text, patch)); + + cl_assert_equal_s(expected, text); + + git__free(text); + git_diff_patch_free(patch); + git_diff_list_free(diff); + git_tree_free(another); + git_tree_free(one); +} |