]>
git.proxmox.com Git - libgit2.git/blob - tests/libgit2/diff/pathspec.c
1 #include "clar_libgit2.h"
2 #include "diff_helpers.h"
4 static git_repository
*g_repo
= NULL
;
6 void test_diff_pathspec__initialize(void)
8 g_repo
= cl_git_sandbox_init("status");
11 void test_diff_pathspec__cleanup(void)
13 cl_git_sandbox_cleanup();
16 void test_diff_pathspec__0(void)
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 };
27 git_pathspec_match_list
*matches
;
33 paths
.strings
= &path
;
34 cl_git_pass(git_pathspec_new(&ps
, &paths
));
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
);
42 cl_git_pass(git_diff_tree_to_tree(&diff
, g_repo
, NULL
, a
, &opts
));
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
);
58 cl_git_pass(git_diff_tree_to_tree(&diff
, g_repo
, a
, b
, &opts
));
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
);
74 cl_git_pass(git_diff_tree_to_workdir(&diff
, g_repo
, a
, &opts
));
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
);
92 git_pathspec_free(ps
);