]>
Commit | Line | Data |
---|---|---|
764df57e BS |
1 | #include "clar_libgit2.h" |
2 | ||
3 | #include "git2/clone.h" | |
4 | #include "repository.h" | |
5 | ||
86a2da6e | 6 | #define LIVE_REPO_URL "git://github.com/libgit2/TestGitRepository" |
822d9dd5 | 7 | |
764df57e | 8 | static git_repository *g_repo; |
44f36f6e | 9 | static git_remote *g_origin = NULL; |
764df57e | 10 | |
65415ea2 | 11 | void test_clone_nonetwork__initialize(void) |
764df57e | 12 | { |
1c7eb971 | 13 | g_repo = NULL; |
7c353afd | 14 | cl_git_pass(git_remote_new(&g_origin, NULL, "origin", cl_git_fixture_url("testrepo.git"), GIT_REMOTE_DEFAULT_FETCH)); |
764df57e BS |
15 | } |
16 | ||
ebecf1e7 | 17 | static void cleanup_repository(void *path) |
764df57e | 18 | { |
9094d30b | 19 | if (g_repo) { |
1c7eb971 | 20 | git_repository_free(g_repo); |
9094d30b SC |
21 | g_repo = NULL; |
22 | } | |
23 | ||
ebecf1e7 | 24 | cl_fixture_cleanup((const char *)path); |
764df57e BS |
25 | } |
26 | ||
65415ea2 | 27 | void test_clone_nonetwork__bad_url(void) |
764df57e | 28 | { |
1c7eb971 | 29 | /* Clone should clean up the mess if the URL isn't a git repository */ |
44f36f6e | 30 | git_remote_free(g_origin); |
7c353afd | 31 | cl_git_pass(git_remote_new(&g_origin, NULL, "origin", "not_a_repo", GIT_REMOTE_DEFAULT_FETCH)); |
44f36f6e BS |
32 | |
33 | cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL)); | |
1c7eb971 | 34 | cl_assert(!git_path_exists("./foo")); |
44f36f6e | 35 | cl_git_fail(git_clone_bare(&g_repo, g_origin, "./foo.git", NULL, NULL)); |
1c7eb971 | 36 | cl_assert(!git_path_exists("./foo.git")); |
764df57e BS |
37 | } |
38 | ||
65415ea2 | 39 | void test_clone_nonetwork__local(void) |
764df57e | 40 | { |
ebecf1e7 | 41 | cl_set_cleanup(&cleanup_repository, "./local"); |
42 | ||
44f36f6e | 43 | cl_git_pass(git_clone(&g_repo, g_origin, "./local", NULL, NULL, NULL)); |
764df57e BS |
44 | } |
45 | ||
65415ea2 | 46 | void test_clone_nonetwork__local_bare(void) |
ebecf1e7 | 47 | { |
ebecf1e7 | 48 | cl_set_cleanup(&cleanup_repository, "./local.git"); |
49 | ||
44f36f6e | 50 | cl_git_pass(git_clone_bare(&g_repo, g_origin, "./local.git", NULL, NULL)); |
ebecf1e7 | 51 | } |
764df57e | 52 | |
65415ea2 | 53 | void test_clone_nonetwork__fail_when_the_target_is_a_file(void) |
ebecf1e7 | 54 | { |
55 | cl_set_cleanup(&cleanup_repository, "./foo"); | |
acdd3d95 | 56 | |
1c7eb971 | 57 | cl_git_mkfile("./foo", "Bar!"); |
44f36f6e BS |
58 | cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL)); |
59 | git_remote_free(g_origin); | |
ebecf1e7 | 60 | } |
61 | ||
65415ea2 | 62 | void test_clone_nonetwork__fail_with_already_existing_but_non_empty_directory(void) |
ebecf1e7 | 63 | { |
64 | cl_set_cleanup(&cleanup_repository, "./foo"); | |
1c7eb971 | 65 | |
1c7eb971 BS |
66 | p_mkdir("./foo", GIT_DIR_MODE); |
67 | cl_git_mkfile("./foo/bar", "Baz!"); | |
44f36f6e BS |
68 | cl_git_fail(git_clone(&g_repo, g_origin, "./foo", NULL, NULL, NULL)); |
69 | git_remote_free(g_origin); | |
764df57e | 70 | } |