@@ -91,7 +91,7 @@ __KHASH_IMPL(
9191
9292static int submodule_alloc (git_submodule * * out , git_repository * repo , const char * name );
9393static git_config_backend * open_gitmodules (git_repository * repo , int gitmod );
94- static git_config * gitmodules_snapshot (git_repository * repo );
94+ static int gitmodules_snapshot (git_config * * snap , git_repository * repo );
9595static int get_url_base (git_buf * url , git_repository * repo );
9696static int lookup_head_remote_key (git_buf * remote_key , git_repository * repo );
9797static int lookup_default_remote (git_remote * * remote , git_repository * repo );
@@ -554,8 +554,11 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
554554 data .map = map ;
555555 data .repo = repo ;
556556
557- if ((mods = gitmodules_snapshot (repo )) == NULL )
557+ if ((error = gitmodules_snapshot (& mods , repo )) < 0 ) {
558+ if (error == GIT_ENOTFOUND )
559+ error = 0 ;
558560 goto cleanup ;
561+ }
559562
560563 data .mods = mods ;
561564 if ((error = git_config_foreach (
@@ -1565,7 +1568,8 @@ int git_submodule_reload(git_submodule *sm, int force)
15651568
15661569 if (!git_repository_is_bare (sm -> repo )) {
15671570 /* refresh config data */
1568- mods = gitmodules_snapshot (sm -> repo );
1571+ if ((error = gitmodules_snapshot (& mods , sm -> repo )) < 0 && error != GIT_ENOTFOUND )
1572+ return error ;
15691573 if (mods != NULL ) {
15701574 error = submodule_read_config (sm , mods );
15711575 git_config_free (mods );
@@ -1969,32 +1973,37 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
19691973}
19701974
19711975/**
1972- * Returns a snapshot of $WORK_TREE/.gitmodules.
1976+ * Requests a snapshot of $WORK_TREE/.gitmodules.
19731977 *
1974- * We ignore any errors and just pretend the file isn't there.
1978+ * Returns GIT_ENOTFOUND in case no .gitmodules file exist
19751979 */
1976- static git_config * gitmodules_snapshot (git_repository * repo )
1980+ static int gitmodules_snapshot (git_config * * snap , git_repository * repo )
19771981{
19781982 const char * workdir = git_repository_workdir (repo );
1979- git_config * mods = NULL , * snap = NULL ;
1983+ git_config * mods = NULL ;
19801984 git_buf path = GIT_BUF_INIT ;
1985+ int error ;
19811986
1982- if (workdir != NULL ) {
1983- if (git_buf_joinpath (& path , workdir , GIT_MODULES_FILE ) != 0 )
1984- return NULL ;
1987+ if (!workdir )
1988+ return GIT_ENOTFOUND ;
19851989
1986- if (git_config_open_ondisk (& mods , path .ptr ) < 0 )
1987- mods = NULL ;
1988- }
1990+ if ((error = git_buf_joinpath (& path , workdir , GIT_MODULES_FILE )) < 0 )
1991+ return error ;
19891992
1990- git_buf_free (& path );
1993+ if ((error = git_config_open_ondisk (& mods , path .ptr )) < 0 )
1994+ goto cleanup ;
1995+
1996+ if ((error = git_config_snapshot (snap , mods )) < 0 )
1997+ goto cleanup ;
1998+
1999+ error = 0 ;
19912000
1992- if ( mods ) {
1993- git_config_snapshot ( & snap , mods );
2001+ cleanup :
2002+ if ( mods )
19942003 git_config_free (mods );
1995- }
2004+ git_buf_free ( & path );
19962005
1997- return snap ;
2006+ return error ;
19982007}
19992008
20002009static git_config_backend * open_gitmodules (
0 commit comments