Commit ceb58739 by Carlos Martín Nieto

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
parents 97c0a85f 08c2d3e9
......@@ -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 {
......
#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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment