]>
Commit | Line | Data |
---|---|---|
a56aacf4 RB |
1 | #include "clar_libgit2.h" |
2 | #include "buffer.h" | |
3 | #include "path.h" | |
4 | #include "posix.h" | |
5 | ||
6 | static git_repository *g_repo = NULL; | |
7 | ||
8 | void test_status_submodules__initialize(void) | |
9 | { | |
10 | git_buf modpath = GIT_BUF_INIT; | |
11 | ||
12 | g_repo = cl_git_sandbox_init("submodules"); | |
13 | ||
14 | cl_fixture_sandbox("testrepo.git"); | |
15 | ||
16 | cl_git_pass(git_buf_sets(&modpath, git_repository_workdir(g_repo))); | |
17 | cl_assert(git_path_dirname_r(&modpath, modpath.ptr) >= 0); | |
18 | cl_git_pass(git_buf_joinpath(&modpath, modpath.ptr, "testrepo.git\n")); | |
19 | ||
20 | p_rename("submodules/gitmodules", "submodules/.gitmodules"); | |
21 | cl_git_append2file("submodules/.gitmodules", modpath.ptr); | |
8e8b6b01 | 22 | git_buf_free(&modpath); |
a56aacf4 RB |
23 | |
24 | p_rename("submodules/testrepo/.gitted", "submodules/testrepo/.git"); | |
25 | } | |
26 | ||
27 | void test_status_submodules__cleanup(void) | |
28 | { | |
29 | cl_git_sandbox_cleanup(); | |
30 | } | |
31 | ||
bfc9ca59 RB |
32 | void test_status_submodules__api(void) |
33 | { | |
34 | git_submodule *sm; | |
35 | ||
36 | cl_assert(git_submodule_lookup(NULL, g_repo, "nonexistent") == GIT_ENOTFOUND); | |
37 | ||
38 | cl_assert(git_submodule_lookup(NULL, g_repo, "modified") == GIT_ENOTFOUND); | |
39 | ||
40 | cl_git_pass(git_submodule_lookup(&sm, g_repo, "testrepo")); | |
41 | cl_assert(sm != NULL); | |
42 | cl_assert_equal_s("testrepo", sm->name); | |
43 | cl_assert_equal_s("testrepo", sm->path); | |
44 | } | |
45 | ||
a56aacf4 | 46 | static int |
277e3041 | 47 | cb_status__submodule_count(const char *p, unsigned int s, void *payload) |
a56aacf4 RB |
48 | { |
49 | volatile int *count = (int *)payload; | |
50 | ||
51 | GIT_UNUSED(p); | |
52 | GIT_UNUSED(s); | |
53 | ||
54 | (*count)++; | |
55 | ||
56 | return 0; | |
57 | } | |
58 | ||
59 | void test_status_submodules__0(void) | |
60 | { | |
61 | int counts = 0; | |
62 | ||
63 | cl_assert(git_path_isdir("submodules/.git")); | |
64 | cl_assert(git_path_isdir("submodules/testrepo/.git")); | |
65 | cl_assert(git_path_isfile("submodules/.gitmodules")); | |
66 | ||
67 | cl_git_pass( | |
277e3041 | 68 | git_status_foreach(g_repo, cb_status__submodule_count, &counts) |
a56aacf4 RB |
69 | ); |
70 | ||
277e3041 | 71 | cl_assert(counts == 6); |
a56aacf4 RB |
72 | } |
73 | ||
74 | static const char *expected_files[] = { | |
75 | ".gitmodules", | |
76 | "added", | |
77 | "deleted", | |
78 | "ignored", | |
79 | "modified", | |
a56aacf4 RB |
80 | "untracked" |
81 | }; | |
82 | ||
83 | static unsigned int expected_status[] = { | |
277e3041 | 84 | GIT_STATUS_WT_MODIFIED, |
a56aacf4 RB |
85 | GIT_STATUS_INDEX_NEW, |
86 | GIT_STATUS_INDEX_DELETED, | |
87 | GIT_STATUS_IGNORED, | |
88 | GIT_STATUS_WT_MODIFIED, | |
a56aacf4 RB |
89 | GIT_STATUS_WT_NEW |
90 | }; | |
91 | ||
92 | static int | |
93 | cb_status__match(const char *p, unsigned int s, void *payload) | |
94 | { | |
95 | volatile int *index = (int *)payload; | |
96 | ||
bfc9ca59 | 97 | cl_assert_equal_s(expected_files[*index], p); |
a56aacf4 RB |
98 | cl_assert(expected_status[*index] == s); |
99 | (*index)++; | |
100 | ||
101 | return 0; | |
102 | } | |
103 | ||
104 | void test_status_submodules__1(void) | |
105 | { | |
106 | int index = 0; | |
107 | ||
108 | cl_assert(git_path_isdir("submodules/.git")); | |
109 | cl_assert(git_path_isdir("submodules/testrepo/.git")); | |
110 | cl_assert(git_path_isfile("submodules/.gitmodules")); | |
111 | ||
112 | cl_git_pass( | |
113 | git_status_foreach(g_repo, cb_status__match, &index) | |
114 | ); | |
115 | ||
277e3041 | 116 | cl_assert(index == 6); |
a56aacf4 | 117 | } |