diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2015-05-05 06:14:40 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2015-06-22 17:02:55 +0200 |
commit | 2278637c4a77df29231b8b7841ba21630ae6c4a3 (patch) | |
tree | adff2e65d9f905d4e45ea38c344d59fd8ddf9b2f | |
parent | d769a3fdda81be4936a3760bd29f39935b32376a (diff) | |
download | libgit2-2278637c4a77df29231b8b7841ba21630ae6c4a3.tar.gz |
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.
-rw-r--r-- | src/submodule.c | 36 |
1 files 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; |