Skip to content

Commit 477b3e0

Browse files
committed
submodule: refuse lookup in bare repositories
While it is technically possible to look up submodules inside of a bare repository by reading the submodule configuration of a specific commit, we do not offer this functionality right now. As such, calling both `git_submodule_lookup` and `git_submodule_foreach` should error out early when these functions encounter a bare repository. While `git_submodule_lookup` already does return an error due to not being able to parse the configuration, `git_submodule_foreach` simply returns success and never invokes the callback function. Fix the issue by having both functions check whether the repository is bare and returning an error in that case.
1 parent a889c05 commit 477b3e0

14 files changed

+49
-0
lines changed

src/submodule.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ int git_submodule_lookup(
209209

210210
assert(repo && name);
211211

212+
if (repo->is_bare) {
213+
giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree");
214+
return -1;
215+
}
216+
212217
if (repo->submodule_cache != NULL) {
213218
khiter_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
214219
if (git_strmap_valid_index(repo->submodule_cache, pos)) {
@@ -549,6 +554,11 @@ int git_submodule_foreach(
549554
int error;
550555
size_t i;
551556

557+
if (repo->is_bare) {
558+
giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree");
559+
return -1;
560+
}
561+
552562
if ((error = git_strmap_alloc(&submodules)) < 0)
553563
return error;
554564

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ref: refs/heads/master
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[core]
2+
repositoryformatversion = 0
3+
filemode = true
4+
bare = true
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
x%�=
2+
�0 F]�)�0�"�I�*�|��-t{?�2�ilV8���$���m��v��k�k*F DA�=(=|=6� �DAv=��A}�&'�O�$=
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
x��[
2+
�0E��*fʤS� ��K�����4ݿw�ׅ�9p�2MC�F�P @���u.�.�p�!�OY�diYU�'̕8X�bPn���6
3+
ħԞ��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.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
P pack-b69d04bb39ac274669e2184e45bd90015d02ef5b.pack
2+

0 commit comments

Comments
 (0)