|
| 1 | +/* test the submodule APIs on repositories where there are no submodules */ |
| 2 | + |
| 3 | +#include "clar_libgit2.h" |
| 4 | +#include "posix.h" |
| 5 | + |
| 6 | +void test_submodule_nosubs__cleanup(void) |
| 7 | +{ |
| 8 | + cl_git_sandbox_cleanup(); |
| 9 | +} |
| 10 | + |
| 11 | +void test_submodule_nosubs__lookup(void) |
| 12 | +{ |
| 13 | + git_repository *repo = cl_git_sandbox_init("status"); |
| 14 | + git_submodule *sm = NULL; |
| 15 | + |
| 16 | + p_mkdir("status/subrepo", 0777); |
| 17 | + cl_git_mkfile("status/subrepo/.git", "gitdir: ../.git"); |
| 18 | + |
| 19 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, repo, "subdir")); |
| 20 | + |
| 21 | + cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, repo, "subrepo")); |
| 22 | + |
| 23 | + cl_git_pass(git_submodule_reload_all(repo, 0)); |
| 24 | + |
| 25 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, repo, "subdir")); |
| 26 | + |
| 27 | + cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, repo, "subrepo")); |
| 28 | +} |
| 29 | + |
| 30 | +void test_submodule_nosubs__immediate_reload(void) |
| 31 | +{ |
| 32 | + git_repository *repo = cl_git_sandbox_init("status"); |
| 33 | + cl_git_pass(git_submodule_reload_all(repo, 0)); |
| 34 | +} |
| 35 | + |
| 36 | +static int fake_submod_cb(git_submodule *sm, const char *n, void *p) |
| 37 | +{ |
| 38 | + GIT_UNUSED(sm); GIT_UNUSED(n); GIT_UNUSED(p); |
| 39 | + return 0; |
| 40 | +} |
| 41 | + |
| 42 | +void test_submodule_nosubs__foreach(void) |
| 43 | +{ |
| 44 | + git_repository *repo = cl_git_sandbox_init("status"); |
| 45 | + cl_git_pass(git_submodule_foreach(repo, fake_submod_cb, NULL)); |
| 46 | +} |
| 47 | + |
| 48 | +void test_submodule_nosubs__add(void) |
| 49 | +{ |
| 50 | + git_repository *repo = cl_git_sandbox_init("status"); |
| 51 | + git_submodule *sm, *sm2; |
| 52 | + |
| 53 | + cl_git_pass(git_submodule_add_setup(&sm, repo, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1)); |
| 54 | + |
| 55 | + cl_git_pass(git_submodule_lookup(&sm2, repo, "submodules/libgit2")); |
| 56 | + git_submodule_free(sm2); |
| 57 | + |
| 58 | + cl_git_pass(git_submodule_foreach(repo, fake_submod_cb, NULL)); |
| 59 | + cl_git_pass(git_submodule_reload_all(repo, 0)); |
| 60 | + |
| 61 | + git_submodule_free(sm); |
| 62 | +} |
| 63 | + |
| 64 | +void test_submodule_nosubs__reload_add_reload(void) |
| 65 | +{ |
| 66 | + git_repository *repo = cl_git_sandbox_init("status"); |
| 67 | + git_submodule *sm; |
| 68 | + |
| 69 | + cl_git_pass(git_submodule_reload_all(repo, 0)); |
| 70 | + |
| 71 | + cl_git_pass(git_submodule_add_setup(&sm, repo, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1)); |
| 72 | + |
| 73 | + cl_git_pass(git_submodule_reload_all(repo, 0)); |
| 74 | + |
| 75 | + cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm)); |
| 76 | + git_submodule_free(sm); |
| 77 | + |
| 78 | + cl_git_pass(git_submodule_lookup(&sm, repo, "submodules/libgit2")); |
| 79 | + cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm)); |
| 80 | + git_submodule_free(sm); |
| 81 | +} |
| 82 | + |
| 83 | +void test_submodule_nosubs__bad_gitmodules(void) |
| 84 | +{ |
| 85 | + git_repository *repo = cl_git_sandbox_init("status"); |
| 86 | + |
| 87 | + cl_git_mkfile("status/.gitmodules", "[submodule \"foobar\"]\tpath=blargle\n\turl=\n\tbranch=\n\tupdate=flooble\n\n"); |
| 88 | + cl_git_fail(git_submodule_reload_all(repo, 0)); |
| 89 | + |
| 90 | + cl_git_rewritefile("status/.gitmodules", "[submodule \"foobar\"]\tpath=blargle\n\turl=\n\tbranch=\n\tupdate=rebase\n\n"); |
| 91 | + cl_git_pass(git_submodule_reload_all(repo, 0)); |
| 92 | + |
| 93 | + cl_git_pass(git_submodule_lookup(NULL, repo, "foobar")); |
| 94 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(NULL, repo, "subdir")); |
| 95 | +} |
0 commit comments