]>
Commit | Line | Data |
---|---|---|
764df57e BS |
1 | #include "clar_libgit2.h" |
2 | ||
3 | #include "git2/clone.h" | |
4 | #include "repository.h" | |
5 | ||
6 | static git_repository *g_repo; | |
7 | ||
8 | void test_clone_clone__initialize(void) | |
9 | { | |
10 | g_repo = NULL; | |
11 | } | |
12 | ||
13 | void test_clone_clone__cleanup(void) | |
14 | { | |
15 | if (g_repo) { | |
16 | git_repository_free(g_repo); | |
17 | g_repo = NULL; | |
18 | } | |
19 | } | |
20 | ||
21 | // TODO: This is copy/pasted from network/remotelocal.c. | |
22 | static void build_local_file_url(git_buf *out, const char *fixture) | |
23 | { | |
24 | const char *in_buf; | |
25 | ||
26 | git_buf path_buf = GIT_BUF_INIT; | |
27 | ||
28 | cl_git_pass(git_path_prettify_dir(&path_buf, fixture, NULL)); | |
29 | cl_git_pass(git_buf_puts(out, "file://")); | |
30 | ||
31 | #ifdef _MSC_VER | |
32 | /* | |
33 | * A FILE uri matches the following format: file://[host]/path | |
34 | * where "host" can be empty and "path" is an absolute path to the resource. | |
35 | * | |
36 | * In this test, no hostname is used, but we have to ensure the leading triple slashes: | |
37 | * | |
38 | * *nix: file:///usr/home/... | |
39 | * Windows: file:///C:/Users/... | |
40 | */ | |
41 | cl_git_pass(git_buf_putc(out, '/')); | |
42 | #endif | |
43 | ||
44 | in_buf = git_buf_cstr(&path_buf); | |
45 | ||
46 | /* | |
47 | * A very hacky Url encoding that only takes care of escaping the spaces | |
48 | */ | |
49 | while (*in_buf) { | |
50 | if (*in_buf == ' ') | |
51 | cl_git_pass(git_buf_puts(out, "%20")); | |
52 | else | |
53 | cl_git_pass(git_buf_putc(out, *in_buf)); | |
54 | ||
55 | in_buf++; | |
56 | } | |
57 | ||
58 | git_buf_free(&path_buf); | |
59 | } | |
60 | ||
61 | ||
62 | void test_clone_clone__bad_url(void) | |
63 | { | |
64 | /* Clone should clean up the mess if the URL isn't a git repository */ | |
65 | cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo")); | |
66 | cl_assert(!git_path_exists("./foo")); | |
67 | cl_git_fail(git_clone_bare(&g_repo, "not_a_repo", "./foo.git")); | |
68 | cl_assert(!git_path_exists("./foo")); | |
69 | } | |
70 | ||
71 | ||
72 | void test_clone_clone__local(void) | |
73 | { | |
74 | git_buf src = GIT_BUF_INIT; | |
75 | build_local_file_url(&src, cl_fixture("testrepo.git")); | |
76 | ||
77 | cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local")); | |
78 | git_repository_free(g_repo); | |
79 | git_futils_rmdir_r("./local", GIT_DIRREMOVAL_FILES_AND_DIRS); | |
80 | cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git")); | |
81 | git_futils_rmdir_r("./local.git", GIT_DIRREMOVAL_FILES_AND_DIRS); | |
82 | } | |
83 | ||
84 | ||
85 | void test_clone_clone__network(void) | |
86 | { | |
87 | cl_git_pass(git_clone(&g_repo, | |
88 | "https://github.com/libgit2/libgit2.git", | |
89 | "./libgit2.git")); | |
90 | git_futils_rmdir_r("./libgit2.git", GIT_DIRREMOVAL_FILES_AND_DIRS); | |
91 | } | |
92 | ||
93 | ||
94 | void test_clone_clone__already_exists(void) | |
95 | { | |
96 | mkdir("./foo", GIT_DIR_MODE); | |
97 | cl_git_fail(git_clone(&g_repo, | |
98 | "https://github.com/libgit2/libgit2.git", | |
99 | "./foo")); | |
100 | git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); | |
101 | } |