]> git.proxmox.com Git - libgit2.git/blame - tests/libgit2/submodule/inject_option.c
Merge https://salsa.debian.org/debian/libgit2 into proxmox/bullseye
[libgit2.git] / tests / libgit2 / submodule / inject_option.c
CommitLineData
6c7cee42
RD
1#include "clar_libgit2.h"
2#include "posix.h"
3#include "path.h"
4#include "submodule_helpers.h"
22a2d3d5 5#include "futils.h"
6c7cee42
RD
6#include "repository.h"
7
8static git_repository *g_repo = NULL;
9
10void test_submodule_inject_option__initialize(void)
11{
12 g_repo = setup_fixture_submodule_simple();
13}
14
15void test_submodule_inject_option__cleanup(void)
16{
17 cl_git_sandbox_cleanup();
18}
19
20static int find_naughty(git_submodule *sm, const char *name, void *payload)
21{
22 int *foundit = (int *) payload;
23
24 GIT_UNUSED(sm);
25
26 if (!git__strcmp("naughty", name))
27 *foundit = true;
28
29 return 0;
30}
31
32void test_submodule_inject_option__url(void)
33{
34 int foundit;
35 git_submodule *sm;
e579e0f7 36 git_str buf = GIT_STR_INIT;
6c7cee42 37
e579e0f7 38 cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
6c7cee42
RD
39 cl_git_rewritefile(buf.ptr,
40 "[submodule \"naughty\"]\n"
41 " path = testrepo\n"
42 " url = -u./payload\n");
e579e0f7 43 git_str_dispose(&buf);
6c7cee42
RD
44
45 /* We do want to find it, but with the appropriate field empty */
46 foundit = 0;
47 cl_git_pass(git_submodule_foreach(g_repo, find_naughty, &foundit));
48 cl_assert_equal_i(1, foundit);
49
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));
53
54 git_submodule_free(sm);
55}
56
57void test_submodule_inject_option__path(void)
58{
59 int foundit;
60 git_submodule *sm;
e579e0f7 61 git_str buf = GIT_STR_INIT;
6c7cee42 62
e579e0f7 63 cl_git_pass(git_str_joinpath(&buf, git_repository_workdir(g_repo), ".gitmodules"));
6c7cee42
RD
64 cl_git_rewritefile(buf.ptr,
65 "[submodule \"naughty\"]\n"
66 " path = --something\n"
67 " url = blah.git\n");
e579e0f7 68 git_str_dispose(&buf);
6c7cee42
RD
69
70 /* We do want to find it, but with the appropriate field empty */
71 foundit = 0;
72 cl_git_pass(git_submodule_foreach(g_repo, find_naughty, &foundit));
73 cl_assert_equal_i(1, foundit);
74
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));
78
79 git_submodule_free(sm);
80}