From 2278637c4a77df29231b8b7841ba21630ae6c4a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Tue, 5 May 2015 06:14:40 +0200 Subject: [PATCH] submodule: correct detection of existing submodules During the cache deletion, the check for whether we consider a submodule to exist got changed regarding submodules which are in the worktree but not configured. Instead of checking for the url field to be populated, check the location where we've found it. --- src/submodule.c | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/submodule.c b/src/submodule.c index 37d420525..f77708516 100644 --- a/src/submodule.c +++ b/src/submodule.c @@ -150,15 +150,11 @@ int git_submodule_lookup( const char *name) /* trailing slash is allowed */ { int error; + unsigned int location; git_submodule *sm; - git_config_backend *mods; assert(repo && name); - mods = open_gitmodules(repo, GITMODULES_EXISTING); - if (!mods) - return -1; - if ((error = submodule_alloc(&sm, repo, name)) < 0) return error; @@ -167,13 +163,28 @@ int git_submodule_lookup( return error; } - /* Didn't find it via the name, maybe it's the path */ - if (!sm->url) { + if ((error = git_submodule_location(&location, sm)) < 0) { + git_submodule_free(sm); + return error; + } + + /* If it's not configured, we need to check for the path */ + if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) { + git_config_backend *mods; const char *pattern = "submodule\\..*\\.path"; fbp_data data = { name, NULL }; - if ((error = git_config_file_foreach_match(mods, pattern, find_by_path, &data)) < 0) + mods = open_gitmodules(repo, GITMODULES_EXISTING); + + if (mods) + error = git_config_file_foreach_match(mods, pattern, find_by_path, &data); + + git_config_file_free(mods); + + if (error < 0) { + git_submodule_free(sm); return error; + } if (data.name) { git__free(sm->name); @@ -189,8 +200,13 @@ int git_submodule_lookup( } } - /* If we didn't find the url, consider it missing */ - if (!sm->url) { + if ((error = git_submodule_location(&location, sm)) < 0) { + git_submodule_free(sm); + return error; + } + + /* If we still haven't found it, do the WD check */ + if (location == 0 || location == GIT_SUBMODULE_STATUS_IN_WD) { git_submodule_free(sm); error = GIT_ENOTFOUND;