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_escape__cleanup(void)
12 cl_git_sandbox_cleanup();
15 #define EVIL_SM_NAME "../../modules/evil"
16 #define EVIL_SM_NAME_WINDOWS "..\\\\..\\\\modules\\\\evil"
17 #define EVIL_SM_NAME_WINDOWS_UNESC "..\\..\\modules\\evil"
19 static int find_evil(git_submodule
*sm
, const char *name
, void *payload
)
21 int *foundit
= (int *) payload
;
25 if (!git__strcmp(EVIL_SM_NAME
, name
) ||
26 !git__strcmp(EVIL_SM_NAME_WINDOWS_UNESC
, name
))
32 void test_submodule_escape__from_gitdir(void)
36 git_str buf
= GIT_STR_INIT
;
37 unsigned int sm_location
;
39 g_repo
= setup_fixture_submodule_simple();
41 cl_git_pass(git_str_joinpath(&buf
, git_repository_workdir(g_repo
), ".gitmodules"));
42 cl_git_rewritefile(buf
.ptr
,
43 "[submodule \"" EVIL_SM_NAME
"\"]\n"
45 " url = ../testrepo.git\n");
46 git_str_dispose(&buf
);
48 /* Find it all the different ways we know about it */
50 cl_git_pass(git_submodule_foreach(g_repo
, find_evil
, &foundit
));
51 cl_assert_equal_i(0, foundit
);
52 cl_git_fail_with(GIT_ENOTFOUND
, git_submodule_lookup(&sm
, g_repo
, EVIL_SM_NAME
));
54 * We do know about this as it's in the index and HEAD, but the data is
55 * incomplete as there is no configured data for it (we pretend it
56 * doesn't exist). This leaves us with an odd situation but it's
57 * consistent with what we would do if we did add a submodule with no
60 cl_git_pass(git_submodule_lookup(&sm
, g_repo
, "testrepo"));
61 cl_git_pass(git_submodule_location(&sm_location
, sm
));
62 cl_assert_equal_i(GIT_SUBMODULE_STATUS_IN_INDEX
| GIT_SUBMODULE_STATUS_IN_HEAD
, sm_location
);
63 git_submodule_free(sm
);
66 void test_submodule_escape__from_gitdir_windows(void)
70 git_str buf
= GIT_STR_INIT
;
71 unsigned int sm_location
;
73 g_repo
= setup_fixture_submodule_simple();
75 cl_git_pass(git_str_joinpath(&buf
, git_repository_workdir(g_repo
), ".gitmodules"));
76 cl_git_rewritefile(buf
.ptr
,
77 "[submodule \"" EVIL_SM_NAME_WINDOWS
"\"]\n"
79 " url = ../testrepo.git\n");
80 git_str_dispose(&buf
);
82 /* Find it all the different ways we know about it */
84 cl_git_pass(git_submodule_foreach(g_repo
, find_evil
, &foundit
));
85 cl_assert_equal_i(0, foundit
);
86 cl_git_fail_with(GIT_ENOTFOUND
, git_submodule_lookup(&sm
, g_repo
, EVIL_SM_NAME_WINDOWS_UNESC
));
88 * We do know about this as it's in the index and HEAD, but the data is
89 * incomplete as there is no configured data for it (we pretend it
90 * doesn't exist). This leaves us with an odd situation but it's
91 * consistent with what we would do if we did add a submodule with no
94 cl_git_pass(git_submodule_lookup(&sm
, g_repo
, "testrepo"));
95 cl_git_pass(git_submodule_location(&sm_location
, sm
));
96 cl_assert_equal_i(GIT_SUBMODULE_STATUS_IN_INDEX
| GIT_SUBMODULE_STATUS_IN_HEAD
, sm_location
);
97 git_submodule_free(sm
);