Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Submodules with bare repo #4305

Merged
merged 3 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ int git_submodule_lookup(

assert(repo && name);

if (repo->is_bare) {
giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree");
return -1;
}

if (repo->submodule_cache != NULL) {
khiter_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
if (git_strmap_valid_index(repo->submodule_cache, pos)) {
Expand Down Expand Up @@ -549,6 +554,11 @@ int git_submodule_foreach(
int error;
size_t i;

if (repo->is_bare) {
giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree");
return -1;
}

if ((error = git_strmap_alloc(&submodules)) < 0)
return error;

Expand Down
1 change: 1 addition & 0 deletions tests/resources/submodules.git/HEAD
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ref: refs/heads/master
4 changes: 4 additions & 0 deletions tests/resources/submodules.git/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[core]
repositoryformatversion = 0
filemode = true
bare = true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
x%�=
�0 F]�)�0�"�I�*�|��-t{?�2�ilV8���$���m��v��k�k*F DA�=(=|=6� �DAv=��A}�&'�O�$=
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
x��[
�0E��*fʤS� ��K�����4ݿw�ׅ�9p�2MC�F�P @���u.�.�p�!�OY�diYU�'̕8X�bPn���6
ħԞ��1[q��}0q���c[W�#�1f��R:���SZ�+Y��+{�td�lv����Om��u�_�}�5�i���` K�
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/resources/submodules.git/objects/info/packs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
P pack-b69d04bb39ac274669e2184e45bd90015d02ef5b.pack

Binary file not shown.
Binary file not shown.
1 change: 1 addition & 0 deletions tests/resources/submodules.git/refs/heads/master
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
97896810b3210244a62a82458b8e0819ecfc6850
34 changes: 33 additions & 1 deletion tests/submodule/lookup.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ void test_submodule_lookup__initialize(void)
g_repo = setup_fixture_submod2();
}

void test_submodule_lookup__cleanup(void)
{
cl_git_sandbox_cleanup();
}

void test_submodule_lookup__simple_lookup(void)
{
assert_submodule_exists(g_repo, "sm_unchanged");
Expand Down Expand Up @@ -389,7 +394,8 @@ void test_submodule_lookup__renamed(void)
cl_assert_equal_i(8, data.count);
}

void test_submodule_lookup_cached(void) {
void test_submodule_lookup__cached(void)
{
git_submodule *sm;
git_submodule *sm2;
/* See that the simple tests still pass. */
Expand All @@ -413,3 +419,29 @@ void test_submodule_lookup_cached(void) {
git_submodule_free(sm);
git_submodule_free(sm2);
}

void test_submodule_lookup__lookup_in_bare_repository_fails(void)
{
git_submodule *sm;

cl_git_sandbox_cleanup();
g_repo = cl_git_sandbox_init("submodules.git");

cl_git_fail(git_submodule_lookup(&sm, g_repo, "nonexisting"));
}

static int foreach_cb(git_submodule *sm, const char *name, void *payload)
{
GIT_UNUSED(sm);
GIT_UNUSED(name);
GIT_UNUSED(payload);
return 0;
}

void test_submodule_lookup__foreach_in_bare_repository_fails(void)
{
cl_git_sandbox_cleanup();
g_repo = cl_git_sandbox_init("submodules.git");

cl_git_fail(git_submodule_foreach(g_repo, foreach_cb, NULL));
}