]>
Commit | Line | Data |
---|---|---|
4b3ec53c | 1 | #include "clar_libgit2.h" |
e579e0f7 | 2 | |
4b3ec53c XL |
3 | #include "path.h" |
4 | ||
5 | static char *gitmodules_altnames[] = { | |
6 | ".gitmodules", | |
7 | ||
8 | /* | |
9 | * Equivalent to the ".git\u200cmodules" string from git but hard-coded | |
10 | * as a UTF-8 sequence | |
11 | */ | |
12 | ".git\xe2\x80\x8cmodules", | |
13 | ||
14 | ".Gitmodules", | |
15 | ".gitmoduleS", | |
16 | ||
17 | ".gitmodules ", | |
18 | ".gitmodules.", | |
19 | ".gitmodules ", | |
20 | ".gitmodules. ", | |
21 | ".gitmodules .", | |
22 | ".gitmodules..", | |
23 | ".gitmodules ", | |
24 | ".gitmodules. ", | |
25 | ".gitmodules . ", | |
26 | ".gitmodules .", | |
27 | ||
28 | ".Gitmodules ", | |
29 | ".Gitmodules.", | |
30 | ".Gitmodules ", | |
31 | ".Gitmodules. ", | |
32 | ".Gitmodules .", | |
33 | ".Gitmodules..", | |
34 | ".Gitmodules ", | |
35 | ".Gitmodules. ", | |
36 | ".Gitmodules . ", | |
37 | ".Gitmodules .", | |
38 | ||
39 | "GITMOD~1", | |
40 | "gitmod~1", | |
41 | "GITMOD~2", | |
42 | "gitmod~3", | |
43 | "GITMOD~4", | |
44 | ||
45 | "GITMOD~1 ", | |
46 | "gitmod~2.", | |
47 | "GITMOD~3 ", | |
48 | "gitmod~4. ", | |
49 | "GITMOD~1 .", | |
50 | "gitmod~2 ", | |
51 | "GITMOD~3. ", | |
52 | "gitmod~4 . ", | |
53 | ||
54 | "GI7EBA~1", | |
55 | "gi7eba~9", | |
56 | ||
57 | "GI7EB~10", | |
58 | "GI7EB~11", | |
59 | "GI7EB~99", | |
60 | "GI7EB~10", | |
61 | "GI7E~100", | |
62 | "GI7E~101", | |
63 | "GI7E~999", | |
64 | "~1000000", | |
65 | "~9999999", | |
66 | }; | |
67 | ||
68 | static char *gitmodules_not_altnames[] = { | |
69 | ".gitmodules x", | |
70 | ".gitmodules .x", | |
71 | ||
72 | " .gitmodules", | |
73 | ||
74 | "..gitmodules", | |
75 | ||
76 | "gitmodules", | |
77 | ||
78 | ".gitmodule", | |
79 | ||
80 | ".gitmodules x ", | |
81 | ".gitmodules .x", | |
82 | ||
83 | "GI7EBA~", | |
84 | "GI7EBA~0", | |
85 | "GI7EBA~~1", | |
86 | "GI7EBA~X", | |
87 | "Gx7EBA~1", | |
88 | "GI7EBX~1", | |
89 | ||
90 | "GI7EB~1", | |
91 | "GI7EB~01", | |
92 | "GI7EB~1", | |
93 | }; | |
94 | ||
95 | void test_path_dotgit__dotgit_modules(void) | |
96 | { | |
97 | size_t i; | |
ac3d33df JK |
98 | |
99 | cl_assert_equal_i(1, git_path_is_gitfile(".gitmodules", strlen(".gitmodules"), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)); | |
100 | cl_assert_equal_i(1, git_path_is_gitfile(".git\xe2\x80\x8cmodules", strlen(".git\xe2\x80\x8cmodules"), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)); | |
4b3ec53c XL |
101 | |
102 | for (i = 0; i < ARRAY_SIZE(gitmodules_altnames); i++) { | |
103 | const char *name = gitmodules_altnames[i]; | |
ac3d33df | 104 | if (!git_path_is_gitfile(name, strlen(name), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)) |
4b3ec53c XL |
105 | cl_fail(name); |
106 | } | |
107 | ||
108 | for (i = 0; i < ARRAY_SIZE(gitmodules_not_altnames); i++) { | |
109 | const char *name = gitmodules_not_altnames[i]; | |
ac3d33df | 110 | if (git_path_is_gitfile(name, strlen(name), GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_GENERIC)) |
4b3ec53c XL |
111 | cl_fail(name); |
112 | } | |
4b3ec53c XL |
113 | } |
114 | ||
115 | void test_path_dotgit__dotgit_modules_symlink(void) | |
116 | { | |
e579e0f7 MB |
117 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".gitmodules", 0, GIT_PATH_REJECT_DOT_GIT_HFS|GIT_PATH_REJECT_DOT_GIT_NTFS)); |
118 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
119 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
120 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".gitmodules . .::$DATA", S_IFLNK, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
121 | } | |
122 | ||
123 | void test_path_dotgit__git_fs_path_is_file(void) | |
124 | { | |
125 | cl_git_fail(git_path_is_gitfile("blob", 4, -1, GIT_PATH_FS_HFS)); | |
126 | cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITIGNORE, GIT_PATH_FS_HFS)); | |
127 | cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITMODULES, GIT_PATH_FS_HFS)); | |
128 | cl_git_pass(git_path_is_gitfile("blob", 4, GIT_PATH_GITFILE_GITATTRIBUTES, GIT_PATH_FS_HFS)); | |
129 | cl_git_fail(git_path_is_gitfile("blob", 4, 3, GIT_PATH_FS_HFS)); | |
130 | } | |
131 | ||
132 | void test_path_dotgit__isvalid_dot_git(void) | |
133 | { | |
134 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0)); | |
135 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git/foo", 0, 0)); | |
136 | cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git", 0, 0)); | |
137 | cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.git/bar", 0, 0)); | |
138 | cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.GIT/bar", 0, 0)); | |
139 | cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/bar/.Git", 0, 0)); | |
140 | ||
141 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); | |
142 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git/foo", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); | |
143 | cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); | |
144 | cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.git/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); | |
145 | cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/.GIT/bar", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); | |
146 | cl_assert_equal_b(false, git_path_is_valid(NULL, "foo/bar/.Git", 0, GIT_PATH_REJECT_DOT_GIT_LITERAL)); | |
147 | ||
148 | cl_assert_equal_b(true, git_path_is_valid(NULL, "!git", 0, 0)); | |
149 | cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/!git", 0, 0)); | |
150 | cl_assert_equal_b(true, git_path_is_valid(NULL, "!git/bar", 0, 0)); | |
151 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig", 0, 0)); | |
152 | cl_assert_equal_b(true, git_path_is_valid(NULL, "foo/.tig", 0, 0)); | |
153 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".tig/bar", 0, 0)); | |
154 | } | |
155 | ||
156 | void test_path_dotgit__isvalid_dotgit_ntfs(void) | |
157 | { | |
158 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git", 0, 0)); | |
159 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git ", 0, 0)); | |
160 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.", 0, 0)); | |
161 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git.. .", 0, 0)); | |
162 | ||
163 | cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1", 0, 0)); | |
164 | cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1 ", 0, 0)); | |
165 | cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.", 0, 0)); | |
166 | cl_assert_equal_b(true, git_path_is_valid(NULL, "git~1.. .", 0, 0)); | |
167 | ||
168 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
169 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
170 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
171 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
172 | ||
173 | cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
174 | cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1 ", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
175 | cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
176 | cl_assert_equal_b(false, git_path_is_valid(NULL, "git~1.. .", 0, GIT_PATH_REJECT_DOT_GIT_NTFS)); | |
177 | } | |
178 | ||
179 | void test_path_dotgit__isvalid_dotgit_with_hfs_ignorables(void) | |
180 | { | |
181 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
182 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
183 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
184 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".g\xe2\x80\x8eIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
185 | cl_assert_equal_b(false, git_path_is_valid(NULL, ".\xe2\x80\x8fgIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
186 | cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xaa.gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
187 | ||
188 | cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x80\xab.\xe2\x80\xacG\xe2\x80\xadI\xe2\x80\xaet", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
189 | cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xab.\xe2\x80\xaaG\xe2\x81\xabI\xe2\x80\xact", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
190 | cl_assert_equal_b(false, git_path_is_valid(NULL, "\xe2\x81\xad.\xe2\x80\xaeG\xef\xbb\xbfIT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
191 | ||
192 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
193 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".g", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
194 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
195 | cl_assert_equal_b(true, git_path_is_valid(NULL, " .git", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
196 | cl_assert_equal_b(true, git_path_is_valid(NULL, "..git\xe2\x80\x8c", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
197 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\xe2\x80\x8dT.", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
198 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2\x80It", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
199 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".\xe2gIt", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
200 | cl_assert_equal_b(true, git_path_is_valid(NULL, "\xe2\x80\xaa.gi", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
201 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x80\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
202 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".gi\x8dT", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
203 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".g\xe2i\x80T\x8e", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
204 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\x80\xbf", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
205 | cl_assert_equal_b(true, git_path_is_valid(NULL, ".git\xe2\xab\x81", 0, GIT_PATH_REJECT_DOT_GIT_HFS)); | |
4b3ec53c | 206 | } |