|
1 | 1 | #include "clar_libgit2.h"
|
2 | 2 | #include "submodule_helpers.h"
|
3 | 3 | #include "posix.h"
|
| 4 | +#include "git2/sys/repository.h" |
4 | 5 |
|
5 | 6 | static git_repository *g_repo = NULL;
|
6 | 7 |
|
@@ -112,3 +113,73 @@ void test_submodule_lookup__foreach(void)
|
112 | 113 | cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
|
113 | 114 | cl_assert_equal_i(8, data.count);
|
114 | 115 | }
|
| 116 | + |
| 117 | +void test_submodule_lookup__lookup_even_with_orphaned_head(void) |
| 118 | +{ |
| 119 | + git_reference *orphan; |
| 120 | + git_submodule *sm; |
| 121 | + |
| 122 | + /* orphan the head */ |
| 123 | + cl_git_pass(git_reference_symbolic_create( |
| 124 | + &orphan, g_repo, "HEAD", "refs/heads/garbage", 1)); |
| 125 | + git_reference_free(orphan); |
| 126 | + |
| 127 | + /* lookup existing */ |
| 128 | + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); |
| 129 | + cl_assert(sm); |
| 130 | + |
| 131 | + /* lookup pending change in .gitmodules that is not in HEAD */ |
| 132 | + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited")); |
| 133 | + cl_assert(sm); |
| 134 | + |
| 135 | + /* lookup pending change in .gitmodules that is neither in HEAD nor index */ |
| 136 | + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); |
| 137 | + cl_assert(sm); |
| 138 | + |
| 139 | + /* lookup git repo subdir that is not added as submodule */ |
| 140 | + cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not-submodule")); |
| 141 | + |
| 142 | + /* lookup existing directory that is not a submodule */ |
| 143 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_dir")); |
| 144 | + |
| 145 | + /* lookup existing file that is not a submodule */ |
| 146 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_file")); |
| 147 | + |
| 148 | + /* lookup non-existent item */ |
| 149 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "no_such_file")); |
| 150 | +} |
| 151 | + |
| 152 | +void test_submodule_lookup__lookup_even_with_missing_index(void) |
| 153 | +{ |
| 154 | + git_index *idx; |
| 155 | + git_submodule *sm; |
| 156 | + |
| 157 | + /* give the repo an empty index */ |
| 158 | + cl_git_pass(git_index_new(&idx)); |
| 159 | + git_repository_set_index(g_repo, idx); |
| 160 | + git_index_free(idx); |
| 161 | + |
| 162 | + /* lookup existing */ |
| 163 | + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_unchanged")); |
| 164 | + cl_assert(sm); |
| 165 | + |
| 166 | + /* lookup pending change in .gitmodules that is not in HEAD */ |
| 167 | + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_added_and_uncommited")); |
| 168 | + cl_assert(sm); |
| 169 | + |
| 170 | + /* lookup pending change in .gitmodules that is neither in HEAD nor index */ |
| 171 | + cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only")); |
| 172 | + cl_assert(sm); |
| 173 | + |
| 174 | + /* lookup git repo subdir that is not added as submodule */ |
| 175 | + cl_assert_equal_i(GIT_EEXISTS, git_submodule_lookup(&sm, g_repo, "not-submodule")); |
| 176 | + |
| 177 | + /* lookup existing directory that is not a submodule */ |
| 178 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_dir")); |
| 179 | + |
| 180 | + /* lookup existing file that is not a submodule */ |
| 181 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "just_a_file")); |
| 182 | + |
| 183 | + /* lookup non-existent item */ |
| 184 | + cl_assert_equal_i(GIT_ENOTFOUND, git_submodule_lookup(&sm, g_repo, "no_such_file")); |
| 185 | +} |
0 commit comments