From 93cf7bb8e26a04d9bd4197c1b938cee352023f63 Mon Sep 17 00:00:00 2001 From: Russell Belfer Date: Wed, 24 Oct 2012 20:56:32 -0700 Subject: 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. --- tests-clar/diff/patch.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'tests-clar/diff/patch.c') 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); +} -- cgit v1.2.1