Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-07-13 19:50:39 +0300
committerCarlos Martín Nieto <cmn@dwim.me>2015-07-13 19:50:39 +0300
commitceb587391312a690e454e1b095c28e09730e022f (patch)
tree593acef4ace60d96ed4da4cde2df723c2fac530b
parent97c0a85fc6e950970a9bf365eb26f9f32a9b3d68 (diff)
parent08c2d3e97c0ee45222b93c214d0b752d0c52ee2d (diff)
Merge pull request #3302 from libgit2/cmn/submodule-foreach-diff-path
List a submodule only once when the path matches a submodule in the index
-rw-r--r--src/submodule.c2
-rw-r--r--tests/submodule/lookup.c18
2 files changed, 19 insertions, 1 deletions
diff --git a/src/submodule.c b/src/submodule.c
index fb3d4bf1e..892c98304 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1647,7 +1647,7 @@ static int submodule_load_from_config(
} else {
khiter_t pos;
git_strmap *map = data->map;
- pos = git_strmap_lookup_index(map, name.ptr);
+ pos = git_strmap_lookup_index(map, path ? path : name.ptr);
if (git_strmap_valid_index(map, pos)) {
sm = git_strmap_value_at(map, pos);
} else {
diff --git a/tests/submodule/lookup.c b/tests/submodule/lookup.c
index 4d40e2279..9b2b3aa19 100644
--- a/tests/submodule/lookup.c
+++ b/tests/submodule/lookup.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "submodule_helpers.h"
#include "git2/sys/repository.h"
+#include "repository.h"
#include "fileops.h"
static git_repository *g_repo = NULL;
@@ -103,8 +104,25 @@ static int sm_lookup_cb(git_submodule *sm, const char *name, void *payload)
void test_submodule_lookup__foreach(void)
{
+ git_config *cfg;
sm_lookup_data data;
+
+ memset(&data, 0, sizeof(data));
+ cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
+ cl_assert_equal_i(8, data.count);
+
memset(&data, 0, sizeof(data));
+
+ /* Change the path for a submodule so it doesn't match the name */
+ cl_git_pass(git_config_open_ondisk(&cfg, "submod2/.gitmodules"));
+
+ cl_git_pass(git_config_set_string(cfg, "submodule.smchangedindex.path", "sm_changed_index"));
+ cl_git_pass(git_config_set_string(cfg, "submodule.smchangedindex.url", "../submod2_target"));
+ cl_git_pass(git_config_delete_entry(cfg, "submodule.sm_changed_index.path"));
+ cl_git_pass(git_config_delete_entry(cfg, "submodule.sm_changed_index.url"));
+
+ git_config_free(cfg);
+
cl_git_pass(git_submodule_foreach(g_repo, sm_lookup_cb, &data));
cl_assert_equal_i(8, data.count);
}