]>
git.proxmox.com Git - libgit2.git/blob - tests/submodule/nosubs.c
1 /* test the submodule APIs on repositories where there are no submodules */
3 #include "clar_libgit2.h"
7 void test_submodule_nosubs__cleanup(void)
9 cl_git_sandbox_cleanup();
12 void test_submodule_nosubs__lookup(void)
14 git_repository
*repo
= cl_git_sandbox_init("status");
15 git_submodule
*sm
= NULL
;
17 p_mkdir("status/subrepo", 0777);
18 cl_git_mkfile("status/subrepo/.git", "gitdir: ../.git");
20 cl_assert_equal_i(GIT_ENOTFOUND
, git_submodule_lookup(&sm
, repo
, "subdir"));
22 cl_assert_equal_i(GIT_EEXISTS
, git_submodule_lookup(&sm
, repo
, "subrepo"));
24 cl_assert_equal_i(GIT_ENOTFOUND
, git_submodule_lookup(&sm
, repo
, "subdir"));
26 cl_assert_equal_i(GIT_EEXISTS
, git_submodule_lookup(&sm
, repo
, "subrepo"));
29 static int fake_submod_cb(git_submodule
*sm
, const char *n
, void *p
)
31 GIT_UNUSED(sm
); GIT_UNUSED(n
); GIT_UNUSED(p
);
35 void test_submodule_nosubs__foreach(void)
37 git_repository
*repo
= cl_git_sandbox_init("status");
38 cl_git_pass(git_submodule_foreach(repo
, fake_submod_cb
, NULL
));
41 void test_submodule_nosubs__add(void)
43 git_repository
*repo
= cl_git_sandbox_init("status");
44 git_submodule
*sm
, *sm2
;
46 cl_git_pass(git_submodule_add_setup(&sm
, repo
, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1));
48 cl_git_pass(git_submodule_lookup(&sm2
, repo
, "submodules/libgit2"));
49 git_submodule_free(sm2
);
51 cl_git_pass(git_submodule_foreach(repo
, fake_submod_cb
, NULL
));
53 git_submodule_free(sm
);
56 void test_submodule_nosubs__bad_gitmodules(void)
58 git_repository
*repo
= cl_git_sandbox_init("status");
60 cl_git_mkfile("status/.gitmodules", "[submodule \"foobar\"]\tpath=blargle\n\turl=\n\tbranch=\n\tupdate=flooble\n\n");
62 cl_git_rewritefile("status/.gitmodules", "[submodule \"foobar\"]\tpath=blargle\n\turl=\n\tbranch=\n\tupdate=rebase\n\n");
64 cl_git_pass(git_submodule_lookup(NULL
, repo
, "foobar"));
65 cl_assert_equal_i(GIT_ENOTFOUND
, git_submodule_lookup(NULL
, repo
, "subdir"));
68 void test_submodule_nosubs__add_and_delete(void)
70 git_repository
*repo
= cl_git_sandbox_init("status");
72 git_buf buf
= GIT_BUF_INIT
;
74 cl_git_fail(git_submodule_lookup(NULL
, repo
, "libgit2"));
75 cl_git_fail(git_submodule_lookup(NULL
, repo
, "submodules/libgit2"));
79 cl_git_pass(git_submodule_add_setup(
80 &sm
, repo
, "https://github.com/libgit2/libgit2.git", "submodules/libgit2", 1));
81 cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm
));
82 cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm
));
83 git_submodule_free(sm
);
85 cl_git_pass(git_futils_readbuffer(&buf
, "status/.gitmodules"));
86 cl_assert(strstr(buf
.ptr
, "[submodule \"submodules/libgit2\"]") != NULL
);
87 cl_assert(strstr(buf
.ptr
, "path = submodules/libgit2") != NULL
);
88 git_buf_dispose(&buf
);
92 cl_git_fail(git_submodule_lookup(&sm
, repo
, "libgit2"));
93 cl_git_pass(git_submodule_lookup(&sm
, repo
, "submodules/libgit2"));
94 cl_assert_equal_s("submodules/libgit2", git_submodule_name(sm
));
95 cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm
));
96 git_submodule_free(sm
);
101 "status/.gitmodules",
102 "[submodule \"libgit2\"]\n"
103 " path = submodules/libgit2\n"
104 " url = https://github.com/libgit2/libgit2.git\n");
106 cl_git_pass(git_submodule_lookup(&sm
, repo
, "libgit2"));
107 cl_assert_equal_s("libgit2", git_submodule_name(sm
));
108 cl_assert_equal_s("submodules/libgit2", git_submodule_path(sm
));
109 git_submodule_free(sm
);
110 cl_git_pass(git_submodule_lookup(&sm
, repo
, "submodules/libgit2"));
111 git_submodule_free(sm
);
113 /* revert name update */
116 "status/.gitmodules",
117 "[submodule \"submodules/libgit2\"]\n"
118 " path = submodules/libgit2\n"
119 " url = https://github.com/libgit2/libgit2.git\n");
121 cl_git_fail(git_submodule_lookup(&sm
, repo
, "libgit2"));
122 cl_git_pass(git_submodule_lookup(&sm
, repo
, "submodules/libgit2"));
123 git_submodule_free(sm
);
125 /* remove completely */
127 cl_must_pass(p_unlink("status/.gitmodules"));
128 cl_git_fail(git_submodule_lookup(&sm
, repo
, "libgit2"));
129 cl_git_fail(git_submodule_lookup(&sm
, repo
, "submodules/libgit2"));