]> git.proxmox.com Git - libgit2.git/blob - tests/core/path.c
Merge pull request #1986 from libgit2/rb/error-handling-cleanups
[libgit2.git] / tests / core / path.c
1 #include "clar_libgit2.h"
2 #include "fileops.h"
3
4 static void
5 check_dirname(const char *A, const char *B)
6 {
7 git_buf dir = GIT_BUF_INIT;
8 char *dir2;
9
10 cl_assert(git_path_dirname_r(&dir, A) >= 0);
11 cl_assert_equal_s(B, dir.ptr);
12 git_buf_free(&dir);
13
14 cl_assert((dir2 = git_path_dirname(A)) != NULL);
15 cl_assert_equal_s(B, dir2);
16 git__free(dir2);
17 }
18
19 static void
20 check_basename(const char *A, const char *B)
21 {
22 git_buf base = GIT_BUF_INIT;
23 char *base2;
24
25 cl_assert(git_path_basename_r(&base, A) >= 0);
26 cl_assert_equal_s(B, base.ptr);
27 git_buf_free(&base);
28
29 cl_assert((base2 = git_path_basename(A)) != NULL);
30 cl_assert_equal_s(B, base2);
31 git__free(base2);
32 }
33
34 static void
35 check_topdir(const char *A, const char *B)
36 {
37 const char *dir;
38
39 cl_assert((dir = git_path_topdir(A)) != NULL);
40 cl_assert_equal_s(B, dir);
41 }
42
43 static void
44 check_joinpath(const char *path_a, const char *path_b, const char *expected_path)
45 {
46 git_buf joined_path = GIT_BUF_INIT;
47
48 cl_git_pass(git_buf_joinpath(&joined_path, path_a, path_b));
49 cl_assert_equal_s(expected_path, joined_path.ptr);
50
51 git_buf_free(&joined_path);
52 }
53
54 static void
55 check_joinpath_n(
56 const char *path_a,
57 const char *path_b,
58 const char *path_c,
59 const char *path_d,
60 const char *expected_path)
61 {
62 git_buf joined_path = GIT_BUF_INIT;
63
64 cl_git_pass(git_buf_join_n(&joined_path, '/', 4,
65 path_a, path_b, path_c, path_d));
66 cl_assert_equal_s(expected_path, joined_path.ptr);
67
68 git_buf_free(&joined_path);
69 }
70
71
72 /* get the dirname of a path */
73 void test_core_path__00_dirname(void)
74 {
75 check_dirname(NULL, ".");
76 check_dirname("", ".");
77 check_dirname("a", ".");
78 check_dirname("/", "/");
79 check_dirname("/usr", "/");
80 check_dirname("/usr/", "/");
81 check_dirname("/usr/lib", "/usr");
82 check_dirname("/usr/lib/", "/usr");
83 check_dirname("/usr/lib//", "/usr");
84 check_dirname("usr/lib", "usr");
85 check_dirname("usr/lib/", "usr");
86 check_dirname("usr/lib//", "usr");
87 check_dirname(".git/", ".");
88
89 check_dirname(REP16("/abc"), REP15("/abc"));
90
91 #ifdef GIT_WIN32
92 check_dirname("C:/path/", "C:/");
93 check_dirname("C:/path", "C:/");
94 check_dirname("//computername/path/", "//computername/");
95 check_dirname("//computername/path", "//computername/");
96 check_dirname("//computername/sub/path/", "//computername/sub");
97 check_dirname("//computername/sub/path", "//computername/sub");
98 #endif
99 }
100
101 /* get the base name of a path */
102 void test_core_path__01_basename(void)
103 {
104 check_basename(NULL, ".");
105 check_basename("", ".");
106 check_basename("a", "a");
107 check_basename("/", "/");
108 check_basename("/usr", "usr");
109 check_basename("/usr/", "usr");
110 check_basename("/usr/lib", "lib");
111 check_basename("/usr/lib//", "lib");
112 check_basename("usr/lib", "lib");
113
114 check_basename(REP16("/abc"), "abc");
115 check_basename(REP1024("/abc"), "abc");
116 }
117
118 /* get the latest component in a path */
119 void test_core_path__02_topdir(void)
120 {
121 check_topdir(".git/", ".git/");
122 check_topdir("/.git/", ".git/");
123 check_topdir("usr/local/.git/", ".git/");
124 check_topdir("./.git/", ".git/");
125 check_topdir("/usr/.git/", ".git/");
126 check_topdir("/", "/");
127 check_topdir("a/", "a/");
128
129 cl_assert(git_path_topdir("/usr/.git") == NULL);
130 cl_assert(git_path_topdir(".") == NULL);
131 cl_assert(git_path_topdir("") == NULL);
132 cl_assert(git_path_topdir("a") == NULL);
133 }
134
135 /* properly join path components */
136 void test_core_path__05_joins(void)
137 {
138 check_joinpath("", "", "");
139 check_joinpath("", "a", "a");
140 check_joinpath("", "/a", "/a");
141 check_joinpath("a", "", "a/");
142 check_joinpath("a", "/", "a/");
143 check_joinpath("a", "b", "a/b");
144 check_joinpath("/", "a", "/a");
145 check_joinpath("/", "", "/");
146 check_joinpath("/a", "/b", "/a/b");
147 check_joinpath("/a", "/b/", "/a/b/");
148 check_joinpath("/a/", "b/", "/a/b/");
149 check_joinpath("/a/", "/b/", "/a/b/");
150
151 check_joinpath("/abcd", "/defg", "/abcd/defg");
152 check_joinpath("/abcd", "/defg/", "/abcd/defg/");
153 check_joinpath("/abcd/", "defg/", "/abcd/defg/");
154 check_joinpath("/abcd/", "/defg/", "/abcd/defg/");
155
156 check_joinpath("/abcdefgh", "/12345678", "/abcdefgh/12345678");
157 check_joinpath("/abcdefgh", "/12345678/", "/abcdefgh/12345678/");
158 check_joinpath("/abcdefgh/", "12345678/", "/abcdefgh/12345678/");
159
160 check_joinpath(REP1024("aaaa"), "", REP1024("aaaa") "/");
161 check_joinpath(REP1024("aaaa/"), "", REP1024("aaaa/"));
162 check_joinpath(REP1024("/aaaa"), "", REP1024("/aaaa") "/");
163
164 check_joinpath(REP1024("aaaa"), REP1024("bbbb"),
165 REP1024("aaaa") "/" REP1024("bbbb"));
166 check_joinpath(REP1024("/aaaa"), REP1024("/bbbb"),
167 REP1024("/aaaa") REP1024("/bbbb"));
168 }
169
170 /* properly join path components for more than one path */
171 void test_core_path__06_long_joins(void)
172 {
173 check_joinpath_n("", "", "", "", "");
174 check_joinpath_n("", "a", "", "", "a/");
175 check_joinpath_n("a", "", "", "", "a/");
176 check_joinpath_n("", "", "", "a", "a");
177 check_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/");
178 check_joinpath_n("a", "b", "", "/c/d", "a/b/c/d");
179 check_joinpath_n("abcd", "efgh", "ijkl", "mnop", "abcd/efgh/ijkl/mnop");
180 check_joinpath_n("abcd/", "efgh/", "ijkl/", "mnop/", "abcd/efgh/ijkl/mnop/");
181 check_joinpath_n("/abcd/", "/efgh/", "/ijkl/", "/mnop/", "/abcd/efgh/ijkl/mnop/");
182
183 check_joinpath_n(REP1024("a"), REP1024("b"), REP1024("c"), REP1024("d"),
184 REP1024("a") "/" REP1024("b") "/"
185 REP1024("c") "/" REP1024("d"));
186 check_joinpath_n(REP1024("/a"), REP1024("/b"), REP1024("/c"), REP1024("/d"),
187 REP1024("/a") REP1024("/b")
188 REP1024("/c") REP1024("/d"));
189 }
190
191
192 static void
193 check_path_to_dir(
194 const char* path,
195 const char* expected)
196 {
197 git_buf tgt = GIT_BUF_INIT;
198
199 git_buf_sets(&tgt, path);
200 cl_git_pass(git_path_to_dir(&tgt));
201 cl_assert_equal_s(expected, tgt.ptr);
202
203 git_buf_free(&tgt);
204 }
205
206 static void
207 check_string_to_dir(
208 const char* path,
209 size_t maxlen,
210 const char* expected)
211 {
212 size_t len = strlen(path);
213 char *buf = git__malloc(len + 2);
214 cl_assert(buf);
215
216 strncpy(buf, path, len + 2);
217
218 git_path_string_to_dir(buf, maxlen);
219
220 cl_assert_equal_s(expected, buf);
221
222 git__free(buf);
223 }
224
225 /* convert paths to dirs */
226 void test_core_path__07_path_to_dir(void)
227 {
228 check_path_to_dir("", "");
229 check_path_to_dir(".", "./");
230 check_path_to_dir("./", "./");
231 check_path_to_dir("a/", "a/");
232 check_path_to_dir("ab", "ab/");
233 /* make sure we try just under and just over an expansion that will
234 * require a realloc
235 */
236 check_path_to_dir("abcdef", "abcdef/");
237 check_path_to_dir("abcdefg", "abcdefg/");
238 check_path_to_dir("abcdefgh", "abcdefgh/");
239 check_path_to_dir("abcdefghi", "abcdefghi/");
240 check_path_to_dir(REP1024("abcd") "/", REP1024("abcd") "/");
241 check_path_to_dir(REP1024("abcd"), REP1024("abcd") "/");
242
243 check_string_to_dir("", 1, "");
244 check_string_to_dir(".", 1, ".");
245 check_string_to_dir(".", 2, "./");
246 check_string_to_dir(".", 3, "./");
247 check_string_to_dir("abcd", 3, "abcd");
248 check_string_to_dir("abcd", 4, "abcd");
249 check_string_to_dir("abcd", 5, "abcd/");
250 check_string_to_dir("abcd", 6, "abcd/");
251 }
252
253 /* join path to itself */
254 void test_core_path__08_self_join(void)
255 {
256 git_buf path = GIT_BUF_INIT;
257 size_t asize = 0;
258
259 asize = path.asize;
260 cl_git_pass(git_buf_sets(&path, "/foo"));
261 cl_assert_equal_s(path.ptr, "/foo");
262 cl_assert(asize < path.asize);
263
264 asize = path.asize;
265 cl_git_pass(git_buf_joinpath(&path, path.ptr, "this is a new string"));
266 cl_assert_equal_s(path.ptr, "/foo/this is a new string");
267 cl_assert(asize < path.asize);
268
269 asize = path.asize;
270 cl_git_pass(git_buf_joinpath(&path, path.ptr, "/grow the buffer, grow the buffer, grow the buffer"));
271 cl_assert_equal_s(path.ptr, "/foo/this is a new string/grow the buffer, grow the buffer, grow the buffer");
272 cl_assert(asize < path.asize);
273
274 git_buf_free(&path);
275 cl_git_pass(git_buf_sets(&path, "/foo/bar"));
276
277 cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "baz"));
278 cl_assert_equal_s(path.ptr, "/bar/baz");
279
280 asize = path.asize;
281 cl_git_pass(git_buf_joinpath(&path, path.ptr + 4, "somethinglongenoughtorealloc"));
282 cl_assert_equal_s(path.ptr, "/baz/somethinglongenoughtorealloc");
283 cl_assert(asize < path.asize);
284
285 git_buf_free(&path);
286 }
287
288 static void check_percent_decoding(const char *expected_result, const char *input)
289 {
290 git_buf buf = GIT_BUF_INIT;
291
292 cl_git_pass(git__percent_decode(&buf, input));
293 cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
294
295 git_buf_free(&buf);
296 }
297
298 void test_core_path__09_percent_decode(void)
299 {
300 check_percent_decoding("abcd", "abcd");
301 check_percent_decoding("a2%", "a2%");
302 check_percent_decoding("a2%3", "a2%3");
303 check_percent_decoding("a2%%3", "a2%%3");
304 check_percent_decoding("a2%3z", "a2%3z");
305 check_percent_decoding("a,", "a%2c");
306 check_percent_decoding("a21", "a2%31");
307 check_percent_decoding("a2%1", "a2%%31");
308 check_percent_decoding("a bc ", "a%20bc%20");
309 check_percent_decoding("Vicent Mart" "\355", "Vicent%20Mart%ED");
310 }
311
312 static void check_fromurl(const char *expected_result, const char *input, int should_fail)
313 {
314 git_buf buf = GIT_BUF_INIT;
315
316 assert(should_fail || expected_result);
317
318 if (!should_fail) {
319 cl_git_pass(git_path_fromurl(&buf, input));
320 cl_assert_equal_s(expected_result, git_buf_cstr(&buf));
321 } else
322 cl_git_fail(git_path_fromurl(&buf, input));
323
324 git_buf_free(&buf);
325 }
326
327 #ifdef GIT_WIN32
328 #define ABS_PATH_MARKER ""
329 #else
330 #define ABS_PATH_MARKER "/"
331 #endif
332
333 void test_core_path__10_fromurl(void)
334 {
335 /* Failing cases */
336 check_fromurl(NULL, "a", 1);
337 check_fromurl(NULL, "http:///c:/Temp%20folder/note.txt", 1);
338 check_fromurl(NULL, "file://c:/Temp%20folder/note.txt", 1);
339 check_fromurl(NULL, "file:////c:/Temp%20folder/note.txt", 1);
340 check_fromurl(NULL, "file:///", 1);
341 check_fromurl(NULL, "file:////", 1);
342 check_fromurl(NULL, "file://servername/c:/Temp%20folder/note.txt", 1);
343
344 /* Passing cases */
345 check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file:///c:/Temp%20folder/note.txt", 0);
346 check_fromurl(ABS_PATH_MARKER "c:/Temp folder/note.txt", "file://localhost/c:/Temp%20folder/note.txt", 0);
347 check_fromurl(ABS_PATH_MARKER "c:/Temp+folder/note.txt", "file:///c:/Temp+folder/note.txt", 0);
348 check_fromurl(ABS_PATH_MARKER "a", "file:///a", 0);
349 }
350
351 typedef struct {
352 int expect_idx;
353 int cancel_after;
354 char **expect;
355 } check_walkup_info;
356
357 #define CANCEL_VALUE 1234
358
359 static int check_one_walkup_step(void *ref, git_buf *path)
360 {
361 check_walkup_info *info = (check_walkup_info *)ref;
362
363 if (!info->cancel_after) {
364 cl_assert_equal_s(info->expect[info->expect_idx], "[CANCEL]");
365 return CANCEL_VALUE;
366 }
367 info->cancel_after--;
368
369 cl_assert(info->expect[info->expect_idx] != NULL);
370 cl_assert_equal_s(info->expect[info->expect_idx], path->ptr);
371 info->expect_idx++;
372
373 return 0;
374 }
375
376 void test_core_path__11_walkup(void)
377 {
378 git_buf p = GIT_BUF_INIT;
379 char *expect[] = {
380 "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL,
381 "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL,
382 "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL,
383 "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", "/a/", "/", NULL,
384 "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL,
385 "/a/b/c/d/e", "/a/b/c/d/", "/a/b/c/", "/a/b/", NULL,
386 "this is a path", NULL,
387 "///a///b///c///d///e///", "///a///b///c///d///", "///a///b///c///", "///a///b///", "///a///", "///", NULL,
388 NULL
389 };
390 char *root[] = { NULL, NULL, "/", "", "/a/b", "/a/b/", NULL, NULL, NULL };
391 int i, j;
392 check_walkup_info info;
393
394 info.expect = expect;
395 info.cancel_after = -1;
396
397 for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
398
399 git_buf_sets(&p, expect[i]);
400
401 info.expect_idx = i;
402 cl_git_pass(
403 git_path_walk_up(&p, root[j], check_one_walkup_step, &info)
404 );
405
406 cl_assert_equal_s(p.ptr, expect[i]);
407
408 /* skip to next run of expectations */
409 while (expect[i] != NULL) i++;
410 }
411
412 git_buf_free(&p);
413 }
414
415 void test_core_path__11a_walkup_cancel(void)
416 {
417 git_buf p = GIT_BUF_INIT;
418 int cancel[] = { 3, 2, 1, 0 };
419 char *expect[] = {
420 "/a/b/c/d/e/", "/a/b/c/d/", "/a/b/c/", "[CANCEL]", NULL,
421 "/a/b/c/d/e", "/a/b/c/d/", "[CANCEL]", NULL,
422 "/a/b/c/d/e", "[CANCEL]", NULL,
423 "[CANCEL]", NULL,
424 NULL
425 };
426 char *root[] = { NULL, NULL, "/", "", NULL };
427 int i, j;
428 check_walkup_info info;
429
430 info.expect = expect;
431
432 for (i = 0, j = 0; expect[i] != NULL; i++, j++) {
433
434 git_buf_sets(&p, expect[i]);
435
436 info.cancel_after = cancel[j];
437 info.expect_idx = i;
438
439 cl_assert_equal_i(
440 CANCEL_VALUE,
441 git_path_walk_up(&p, root[j], check_one_walkup_step, &info)
442 );
443
444 /* skip to next run of expectations */
445 while (expect[i] != NULL) i++;
446 }
447
448 git_buf_free(&p);
449 }
450
451 void test_core_path__12_offset_to_path_root(void)
452 {
453 cl_assert(git_path_root("non/rooted/path") == -1);
454 cl_assert(git_path_root("/rooted/path") == 0);
455
456 #ifdef GIT_WIN32
457 /* Windows specific tests */
458 cl_assert(git_path_root("C:non/rooted/path") == -1);
459 cl_assert(git_path_root("C:/rooted/path") == 2);
460 cl_assert(git_path_root("//computername/sharefolder/resource") == 14);
461 cl_assert(git_path_root("//computername/sharefolder") == 14);
462 cl_assert(git_path_root("//computername") == -1);
463 #endif
464 }
465
466 #define NON_EXISTING_FILEPATH "i_hope_i_do_not_exist"
467
468 void test_core_path__13_cannot_prettify_a_non_existing_file(void)
469 {
470 git_buf p = GIT_BUF_INIT;
471
472 cl_must_pass(git_path_exists(NON_EXISTING_FILEPATH) == false);
473 cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH, NULL));
474 cl_assert_equal_i(GIT_ENOTFOUND, git_path_prettify(&p, NON_EXISTING_FILEPATH "/so-do-i", NULL));
475
476 git_buf_free(&p);
477 }
478
479 void test_core_path__14_apply_relative(void)
480 {
481 git_buf p = GIT_BUF_INIT;
482
483 cl_git_pass(git_buf_sets(&p, "/this/is/a/base"));
484
485 cl_git_pass(git_path_apply_relative(&p, "../test"));
486 cl_assert_equal_s("/this/is/a/test", p.ptr);
487
488 cl_git_pass(git_path_apply_relative(&p, "../../the/./end"));
489 cl_assert_equal_s("/this/is/the/end", p.ptr);
490
491 cl_git_pass(git_path_apply_relative(&p, "./of/this/../the/string"));
492 cl_assert_equal_s("/this/is/the/end/of/the/string", p.ptr);
493
494 cl_git_pass(git_path_apply_relative(&p, "../../../../../.."));
495 cl_assert_equal_s("/this/", p.ptr);
496
497 cl_git_pass(git_path_apply_relative(&p, "../"));
498 cl_assert_equal_s("/", p.ptr);
499
500 cl_git_fail(git_path_apply_relative(&p, "../../.."));
501
502
503 cl_git_pass(git_buf_sets(&p, "d:/another/test"));
504
505 cl_git_pass(git_path_apply_relative(&p, "../.."));
506 cl_assert_equal_s("d:/", p.ptr);
507
508 cl_git_pass(git_path_apply_relative(&p, "from/here/to/../and/./back/."));
509 cl_assert_equal_s("d:/from/here/and/back/", p.ptr);
510
511
512 cl_git_pass(git_buf_sets(&p, "https://my.url.com/test.git"));
513
514 cl_git_pass(git_path_apply_relative(&p, "../another.git"));
515 cl_assert_equal_s("https://my.url.com/another.git", p.ptr);
516
517 cl_git_pass(git_path_apply_relative(&p, "../full/path/url.patch"));
518 cl_assert_equal_s("https://my.url.com/full/path/url.patch", p.ptr);
519
520 cl_git_pass(git_path_apply_relative(&p, ".."));
521 cl_assert_equal_s("https://my.url.com/full/path/", p.ptr);
522
523 cl_git_pass(git_path_apply_relative(&p, "../../../"));
524 cl_assert_equal_s("https://", p.ptr);
525
526
527 cl_git_pass(git_buf_sets(&p, "../../this/is/relative"));
528
529 cl_git_pass(git_path_apply_relative(&p, "../../preserves/the/prefix"));
530 cl_assert_equal_s("../../this/preserves/the/prefix", p.ptr);
531
532 cl_git_pass(git_path_apply_relative(&p, "../../../../that"));
533 cl_assert_equal_s("../../that", p.ptr);
534
535 cl_git_pass(git_path_apply_relative(&p, "../there"));
536 cl_assert_equal_s("../../there", p.ptr);
537 git_buf_free(&p);
538 }
539
540 static void assert_resolve_relative(
541 git_buf *buf, const char *expected, const char *path)
542 {
543 cl_git_pass(git_buf_sets(buf, path));
544 cl_git_pass(git_path_resolve_relative(buf, 0));
545 cl_assert_equal_s(expected, buf->ptr);
546 }
547
548 void test_core_path__15_resolve_relative(void)
549 {
550 git_buf buf = GIT_BUF_INIT;
551
552 assert_resolve_relative(&buf, "", "");
553 assert_resolve_relative(&buf, "", ".");
554 assert_resolve_relative(&buf, "", "./");
555 assert_resolve_relative(&buf, "..", "..");
556 assert_resolve_relative(&buf, "../", "../");
557 assert_resolve_relative(&buf, "..", "./..");
558 assert_resolve_relative(&buf, "../", "./../");
559 assert_resolve_relative(&buf, "../", "../.");
560 assert_resolve_relative(&buf, "../", ".././");
561 assert_resolve_relative(&buf, "../..", "../..");
562 assert_resolve_relative(&buf, "../../", "../../");
563
564 assert_resolve_relative(&buf, "/", "/");
565 assert_resolve_relative(&buf, "/", "/.");
566
567 assert_resolve_relative(&buf, "", "a/..");
568 assert_resolve_relative(&buf, "", "a/../");
569 assert_resolve_relative(&buf, "", "a/../.");
570
571 assert_resolve_relative(&buf, "/a", "/a");
572 assert_resolve_relative(&buf, "/a/", "/a/.");
573 assert_resolve_relative(&buf, "/", "/a/../");
574 assert_resolve_relative(&buf, "/", "/a/../.");
575 assert_resolve_relative(&buf, "/", "/a/.././");
576
577 assert_resolve_relative(&buf, "a", "a");
578 assert_resolve_relative(&buf, "a/", "a/");
579 assert_resolve_relative(&buf, "a/", "a/.");
580 assert_resolve_relative(&buf, "a/", "a/./");
581
582 assert_resolve_relative(&buf, "a/b", "a//b");
583 assert_resolve_relative(&buf, "a/b/c", "a/b/c");
584 assert_resolve_relative(&buf, "b/c", "./b/c");
585 assert_resolve_relative(&buf, "a/c", "a/./c");
586 assert_resolve_relative(&buf, "a/b/", "a/b/.");
587
588 assert_resolve_relative(&buf, "/a/b/c", "///a/b/c");
589 assert_resolve_relative(&buf, "/", "////");
590 assert_resolve_relative(&buf, "/a", "///a");
591 assert_resolve_relative(&buf, "/", "///.");
592 assert_resolve_relative(&buf, "/", "///a/..");
593
594 assert_resolve_relative(&buf, "../../path", "../../test//../././path");
595 assert_resolve_relative(&buf, "../d", "a/b/../../../c/../d");
596
597 cl_git_pass(git_buf_sets(&buf, "/.."));
598 cl_git_fail(git_path_resolve_relative(&buf, 0));
599
600 cl_git_pass(git_buf_sets(&buf, "/./.."));
601 cl_git_fail(git_path_resolve_relative(&buf, 0));
602
603 cl_git_pass(git_buf_sets(&buf, "/.//.."));
604 cl_git_fail(git_path_resolve_relative(&buf, 0));
605
606 cl_git_pass(git_buf_sets(&buf, "/../."));
607 cl_git_fail(git_path_resolve_relative(&buf, 0));
608
609 cl_git_pass(git_buf_sets(&buf, "/../.././../a"));
610 cl_git_fail(git_path_resolve_relative(&buf, 0));
611
612 cl_git_pass(git_buf_sets(&buf, "////.."));
613 cl_git_fail(git_path_resolve_relative(&buf, 0));
614
615 /* things that start with Windows network paths */
616 #ifdef GIT_WIN32
617 assert_resolve_relative(&buf, "//a/b/c", "//a/b/c");
618 assert_resolve_relative(&buf, "//a/", "//a/b/..");
619 assert_resolve_relative(&buf, "//a/b/c", "//a/Q/../b/x/y/../../c");
620
621 cl_git_pass(git_buf_sets(&buf, "//a/b/../.."));
622 cl_git_fail(git_path_resolve_relative(&buf, 0));
623 #else
624 assert_resolve_relative(&buf, "/a/b/c", "//a/b/c");
625 assert_resolve_relative(&buf, "/a/", "//a/b/..");
626 assert_resolve_relative(&buf, "/a/b/c", "//a/Q/../b/x/y/../../c");
627 assert_resolve_relative(&buf, "/", "//a/b/../..");
628 #endif
629
630 git_buf_free(&buf);
631 }