]> git.proxmox.com Git - libgit2.git/blobdiff - src/submodule.c
New upstream version 0.27.0+dfsg.1
[libgit2.git] / src / submodule.c
index ddd4b0663709afe1069cf6c90f4aae3b15a382e2..3ec0307b3428226e923c175fa58de82c212b5cf1 100644 (file)
@@ -5,7 +5,8 @@
  * a Linking Exception. For full terms see the included COPYING file.
  */
 
-#include "common.h"
+#include "submodule.h"
+
 #include "git2/config.h"
 #include "git2/sys/config.h"
 #include "git2/types.h"
@@ -17,7 +18,6 @@
 #include "config_file.h"
 #include "config.h"
 #include "repository.h"
-#include "submodule.h"
 #include "tree.h"
 #include "iterator.h"
 #include "path.h"
@@ -209,6 +209,11 @@ int git_submodule_lookup(
 
        assert(repo && name);
 
+       if (repo->is_bare) {
+               giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree");
+               return -1;
+       }
+
        if (repo->submodule_cache != NULL) {
                khiter_t pos = git_strmap_lookup_index(repo->submodule_cache, name);
                if (git_strmap_valid_index(repo->submodule_cache, pos)) {
@@ -549,6 +554,11 @@ int git_submodule_foreach(
        int error;
        size_t i;
 
+       if (repo->is_bare) {
+               giterr_set(GITERR_SUBMODULE, "cannot get submodules without a working tree");
+               return -1;
+       }
+
        if ((error = git_strmap_alloc(&submodules)) < 0)
                return error;
 
@@ -1950,7 +1960,7 @@ static git_config_backend *open_gitmodules(
                        if (git_config_file__ondisk(&mods, path.ptr) < 0)
                                mods = NULL;
                        /* open should only fail here if the file is malformed */
-                       else if (git_config_file_open(mods, GIT_CONFIG_LEVEL_LOCAL) < 0) {
+                       else if (git_config_file_open(mods, GIT_CONFIG_LEVEL_LOCAL, repo) < 0) {
                                git_config_file_free(mods);
                                mods = NULL;
                        }