@@ -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 );
@@ -509,8 +509,11 @@ int git_submodule__map(git_repository *repo, git_strmap *map)
509509 data .map = map ;
510510 data .repo = repo ;
511511
512- if ((mods = gitmodules_snapshot (repo )) == NULL )
512+ if ((error = gitmodules_snapshot (& mods , repo )) < 0 ) {
513+ if (error == GIT_ENOTFOUND )
514+ error = 0 ;
513515 goto cleanup ;
516+ }
514517
515518 data .mods = mods ;
516519 if ((error = git_config_foreach (
@@ -1511,7 +1514,8 @@ int git_submodule_reload(git_submodule *sm, int force)
15111514
15121515 if (!git_repository_is_bare (sm -> repo )) {
15131516 /* refresh config data */
1514- mods = gitmodules_snapshot (sm -> repo );
1517+ if ((error = gitmodules_snapshot (& mods , sm -> repo )) < 0 && error != GIT_ENOTFOUND )
1518+ return error ;
15151519 if (mods != NULL ) {
15161520 error = submodule_read_config (sm , mods );
15171521 git_config_free (mods );
@@ -1915,32 +1919,37 @@ static int submodule_load_from_wd_lite(git_submodule *sm)
19151919}
19161920
19171921/**
1918- * Returns a snapshot of $WORK_TREE/.gitmodules.
1922+ * Requests a snapshot of $WORK_TREE/.gitmodules.
19191923 *
1920- * We ignore any errors and just pretend the file isn't there.
1924+ * Returns GIT_ENOTFOUND in case no .gitmodules file exist
19211925 */
1922- static git_config * gitmodules_snapshot (git_repository * repo )
1926+ static int gitmodules_snapshot (git_config * * snap , git_repository * repo )
19231927{
19241928 const char * workdir = git_repository_workdir (repo );
1925- git_config * mods = NULL , * snap = NULL ;
1929+ git_config * mods = NULL ;
19261930 git_buf path = GIT_BUF_INIT ;
1931+ int error ;
19271932
1928- if (workdir != NULL ) {
1929- if (git_buf_joinpath (& path , workdir , GIT_MODULES_FILE ) != 0 )
1930- return NULL ;
1933+ if (!workdir )
1934+ return GIT_ENOTFOUND ;
19311935
1932- if (git_config_open_ondisk (& mods , path .ptr ) < 0 )
1933- mods = NULL ;
1934- }
1936+ if ((error = git_buf_joinpath (& path , workdir , GIT_MODULES_FILE )) < 0 )
1937+ return error ;
19351938
1936- git_buf_free (& path );
1939+ if ((error = git_config_open_ondisk (& mods , path .ptr )) < 0 )
1940+ goto cleanup ;
1941+
1942+ if ((error = git_config_snapshot (snap , mods )) < 0 )
1943+ goto cleanup ;
1944+
1945+ error = 0 ;
19371946
1938- if ( mods ) {
1939- git_config_snapshot ( & snap , mods );
1947+ cleanup :
1948+ if ( mods )
19401949 git_config_free (mods );
1941- }
1950+ git_buf_free ( & path );
19421951
1943- return snap ;
1952+ return error ;
19441953}
19451954
19461955static git_config_backend * open_gitmodules (
0 commit comments