]> git.proxmox.com Git - libgit2.git/blob - tests/libgit2/diff/pathspec.c
New upstream version 1.5.0+ds
[libgit2.git] / tests / libgit2 / diff / pathspec.c
1 #include "clar_libgit2.h"
2 #include "diff_helpers.h"
3
4 static git_repository *g_repo = NULL;
5
6 void test_diff_pathspec__initialize(void)
7 {
8 g_repo = cl_git_sandbox_init("status");
9 }
10
11 void test_diff_pathspec__cleanup(void)
12 {
13 cl_git_sandbox_cleanup();
14 }
15
16 void test_diff_pathspec__0(void)
17 {
18 const char *a_commit = "26a125ee"; /* the current HEAD */
19 const char *b_commit = "0017bd4a"; /* the start */
20 git_tree *a = resolve_commit_oid_to_tree(g_repo, a_commit);
21 git_tree *b = resolve_commit_oid_to_tree(g_repo, b_commit);
22 git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
23 git_diff *diff = NULL;
24 git_strarray paths = { NULL, 1 };
25 char *path;
26 git_pathspec *ps;
27 git_pathspec_match_list *matches;
28
29 cl_assert(a);
30 cl_assert(b);
31
32 path = "*_file";
33 paths.strings = &path;
34 cl_git_pass(git_pathspec_new(&ps, &paths));
35
36 cl_git_pass(git_pathspec_match_tree(&matches, a, GIT_PATHSPEC_DEFAULT, ps));
37 cl_assert_equal_i(7, (int)git_pathspec_match_list_entrycount(matches));
38 cl_assert_equal_s("current_file", git_pathspec_match_list_entry(matches,0));
39 cl_assert(git_pathspec_match_list_diff_entry(matches,0) == NULL);
40 git_pathspec_match_list_free(matches);
41
42 cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, NULL, a, &opts));
43
44 cl_git_pass(git_pathspec_match_diff(
45 &matches, diff, GIT_PATHSPEC_DEFAULT, ps));
46 cl_assert_equal_i(7, (int)git_pathspec_match_list_entrycount(matches));
47 cl_assert(git_pathspec_match_list_diff_entry(matches, 0) != NULL);
48 cl_assert(git_pathspec_match_list_entry(matches, 0) == NULL);
49 cl_assert_equal_s("current_file",
50 git_pathspec_match_list_diff_entry(matches,0)->new_file.path);
51 cl_assert_equal_i(GIT_DELTA_ADDED,
52 (int)git_pathspec_match_list_diff_entry(matches,0)->status);
53 git_pathspec_match_list_free(matches);
54
55 git_diff_free(diff);
56 diff = NULL;
57
58 cl_git_pass(git_diff_tree_to_tree(&diff, g_repo, a, b, &opts));
59
60 cl_git_pass(git_pathspec_match_diff(
61 &matches, diff, GIT_PATHSPEC_DEFAULT, ps));
62 cl_assert_equal_i(3, (int)git_pathspec_match_list_entrycount(matches));
63 cl_assert(git_pathspec_match_list_diff_entry(matches, 0) != NULL);
64 cl_assert(git_pathspec_match_list_entry(matches, 0) == NULL);
65 cl_assert_equal_s("subdir/current_file",
66 git_pathspec_match_list_diff_entry(matches,0)->new_file.path);
67 cl_assert_equal_i(GIT_DELTA_DELETED,
68 (int)git_pathspec_match_list_diff_entry(matches,0)->status);
69 git_pathspec_match_list_free(matches);
70
71 git_diff_free(diff);
72 diff = NULL;
73
74 cl_git_pass(git_diff_tree_to_workdir(&diff, g_repo, a, &opts));
75
76 cl_git_pass(git_pathspec_match_diff(
77 &matches, diff, GIT_PATHSPEC_DEFAULT, ps));
78 cl_assert_equal_i(4, (int)git_pathspec_match_list_entrycount(matches));
79 cl_assert(git_pathspec_match_list_diff_entry(matches, 0) != NULL);
80 cl_assert(git_pathspec_match_list_entry(matches, 0) == NULL);
81 cl_assert_equal_s("modified_file",
82 git_pathspec_match_list_diff_entry(matches,0)->new_file.path);
83 cl_assert_equal_i(GIT_DELTA_MODIFIED,
84 (int)git_pathspec_match_list_diff_entry(matches,0)->status);
85 git_pathspec_match_list_free(matches);
86
87 git_diff_free(diff);
88 diff = NULL;
89
90 git_tree_free(a);
91 git_tree_free(b);
92 git_pathspec_free(ps);
93 }