Merge pull request #3286 from libgit2/cmn/submodule-duplicate Correctly delimit the keys for submodule lookup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/src/submodule.c b/src/submodule.c
index 17e1a35..fb3d4bf 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1385,7 +1385,7 @@ int git_submodule_reload(git_submodule *sm, int force)
git_buf_sets(&path, "submodule\\.");
git_buf_text_puts_escape_regex(&path, sm->name);
- git_buf_puts(&path, ".*");
+ git_buf_puts(&path, "\\..*");
if (git_buf_oom(&path)) {
error = -1;
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index cddbdcf..4d40e22 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -269,3 +269,26 @@ void test_submodule_lookup__just_added(void)
refute_submodule_exists(g_repo, "sm_just_added_head", GIT_EEXISTS);
}
+/* Test_App and Test_App2 are fairly similar names, make sure we load the right one */
+void test_submodule_lookup__prefix_name(void)
+{
+ git_submodule *sm;
+
+ cl_git_rewritefile("submod2/.gitmodules",
+ "[submodule \"Test_App\"]\n"
+ " path = Test_App\n"
+ " url = ../Test_App\n"
+ "[submodule \"Test_App2\"]\n"
+ " path = Test_App2\n"
+ " url = ../Test_App\n");
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "Test_App"));
+ cl_assert_equal_s("Test_App", git_submodule_name(sm));
+
+ git_submodule_free(sm);
+
+ cl_git_pass(git_submodule_lookup(&sm, g_repo, "Test_App2"));
+ cl_assert_equal_s("Test_App2", git_submodule_name(sm));
+
+ git_submodule_free(sm);
+}