summaryrefslogtreecommitdiff
path: root/tests-clar/diff/patch.c
diff options
context:
space:
mode:
authorVicent Martí <vicent@github.com>2012-10-30 12:04:28 -0700
committerVicent Martí <vicent@github.com>2012-10-30 12:04:28 -0700
commitefde422553e1181933d0bc9d7112740e858a847b (patch)
treee48cf99ea2d89a0240597fd6e7eb61082bbc6f5b /tests-clar/diff/patch.c
parentc4a9ded0f9d8edd400cce0df5901af5b8c103147 (diff)
parentcb7180a6e2bb7e5912c16d2109f273c75731a607 (diff)
downloadlibgit2-efde422553e1181933d0bc9d7112740e858a847b.tar.gz
Merge pull request #1017 from arrbee/diff-patch-to-str
Add git_diff_patch_to_str API
Diffstat (limited to 'tests-clar/diff/patch.c')
-rw-r--r--tests-clar/diff/patch.c30
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);
+}