summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/submodule.c7
-rw-r--r--tests/submodule/lookup.c26
2 files changed, 33 insertions, 0 deletions
diff --git a/src/submodule.c b/src/submodule.c
index b927b17b6..b832286f7 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -231,6 +231,13 @@ static int load_submodule_names(git_strmap *out, git_repository *repo, git_confi
fdot = strchr(entry->name, '.');
ldot = strrchr(entry->name, '.');
+ if (git_strmap_exists(out, entry->value)) {
+ giterr_set(GITERR_SUBMODULE,
+ "duplicated submodule path '%s'", entry->value);
+ error = -1;
+ goto out;
+ }
+
git_buf_clear(&buf);
git_buf_put(&buf, fdot + 1, ldot - fdot - 1);
isvalid = git_submodule_name_is_valid(repo, buf.ptr, 0);
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index 170be5a44..5db5c2dd6 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -132,6 +132,32 @@ void test_submodule_lookup__foreach(void)
cl_assert_equal_i(8, data.count);
}
+static int sm_dummy_cb(git_submodule *sm, const char *name, void *payload)
+{
+ GIT_UNUSED(sm);
+ GIT_UNUSED(name);
+ GIT_UNUSED(payload);
+ return 0;
+}
+
+void test_submodule_lookup__duplicated_path(void)
+{
+ /*
+ * Manually invoke cleanup methods to remove leftovers
+ * from `setup_fixture_submod2`
+ */
+ cl_git_sandbox_cleanup();
+ cl_fixture_cleanup("submod2_target");
+
+ g_repo = setup_fixture_submodules();
+
+ /*
+ * This should fail, as the submodules repo has an
+ * invalid gitmodules file with duplicated paths.
+ */
+ cl_git_fail(git_submodule_foreach(g_repo, sm_dummy_cb, NULL));
+}
+
void test_submodule_lookup__lookup_even_with_unborn_head(void)
{
git_reference *head;