]>
git.proxmox.com Git - libgit2.git/blob - tests/submodule/inject_option.c
1 #include "clar_libgit2.h"
4 #include "submodule_helpers.h"
6 #include "repository.h"
8 static git_repository
*g_repo
= NULL
;
10 void test_submodule_inject_option__initialize(void)
12 g_repo
= setup_fixture_submodule_simple();
15 void test_submodule_inject_option__cleanup(void)
17 cl_git_sandbox_cleanup();
20 static int find_naughty(git_submodule
*sm
, const char *name
, void *payload
)
22 int *foundit
= (int *) payload
;
26 if (!git__strcmp("naughty", name
))
32 void test_submodule_inject_option__url(void)
36 git_str buf
= GIT_STR_INIT
;
38 cl_git_pass(git_str_joinpath(&buf
, git_repository_workdir(g_repo
), ".gitmodules"));
39 cl_git_rewritefile(buf
.ptr
,
40 "[submodule \"naughty\"]\n"
42 " url = -u./payload\n");
43 git_str_dispose(&buf
);
45 /* We do want to find it, but with the appropriate field empty */
47 cl_git_pass(git_submodule_foreach(g_repo
, find_naughty
, &foundit
));
48 cl_assert_equal_i(1, foundit
);
50 cl_git_pass(git_submodule_lookup(&sm
, g_repo
, "naughty"));
51 cl_assert_equal_s("testrepo", git_submodule_path(sm
));
52 cl_assert_equal_p(NULL
, git_submodule_url(sm
));
54 git_submodule_free(sm
);
57 void test_submodule_inject_option__path(void)
61 git_str buf
= GIT_STR_INIT
;
63 cl_git_pass(git_str_joinpath(&buf
, git_repository_workdir(g_repo
), ".gitmodules"));
64 cl_git_rewritefile(buf
.ptr
,
65 "[submodule \"naughty\"]\n"
66 " path = --something\n"
68 git_str_dispose(&buf
);
70 /* We do want to find it, but with the appropriate field empty */
72 cl_git_pass(git_submodule_foreach(g_repo
, find_naughty
, &foundit
));
73 cl_assert_equal_i(1, foundit
);
75 cl_git_pass(git_submodule_lookup(&sm
, g_repo
, "naughty"));
76 cl_assert_equal_s("naughty", git_submodule_path(sm
));
77 cl_assert_equal_s("blah.git", git_submodule_url(sm
));
79 git_submodule_free(sm
);