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.
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
diff --git a/src/submodule.c b/src/submodule.c
index 37d4205..f777085 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;