Skip to content

Commit 936b184

Browse files
authored
Merge pull request libgit2#6434 from tagesuhu/main
Fixes libgit2#6433: git_submodule_update fails to update configured but missing submodule
2 parents 12832ba + 3f4b91b commit 936b184

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/libgit2/submodule.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,11 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
13381338
/* Get the status of the submodule to determine if it is already initialized */
13391339
if ((error = git_submodule_status(&submodule_status, sm->repo, sm->name, GIT_SUBMODULE_IGNORE_UNSPECIFIED)) < 0)
13401340
goto done;
1341-
1341+
1342+
/* If the submodule is configured but hasn't been added, skip it */
1343+
if (submodule_status == GIT_SUBMODULE_STATUS_IN_CONFIG)
1344+
goto done;
1345+
13421346
/*
13431347
* If submodule work dir is not already initialized, check to see
13441348
* what we need to do (initialize, clone, return error...)

tests/libgit2/submodule/update.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,26 @@ void test_submodule_update__update_and_init_submodule(void)
206206
git_submodule_free(sm);
207207
}
208208

209+
void test_submodule_update__update_skip_configured_missing_submodule(void)
210+
{
211+
git_submodule *sm;
212+
git_submodule_update_options update_options = GIT_SUBMODULE_UPDATE_OPTIONS_INIT;
213+
unsigned int submodule_status = 0;
214+
215+
g_repo = setup_fixture_submod2();
216+
217+
/* get the submodule */
218+
cl_git_pass(git_submodule_lookup(&sm, g_repo, "sm_gitmodules_only"));
219+
220+
cl_git_pass(git_submodule_status(&submodule_status, g_repo, "sm_gitmodules_only", GIT_SUBMODULE_IGNORE_UNSPECIFIED));
221+
cl_assert_equal_i(submodule_status, GIT_SUBMODULE_STATUS_IN_CONFIG);
222+
223+
/* update (with option to initialize sub repo) */
224+
cl_git_pass(git_submodule_update(sm, 1, &update_options));
225+
226+
git_submodule_free(sm);
227+
}
228+
209229
void test_submodule_update__update_already_checked_out_submodule(void)
210230
{
211231
git_submodule *sm = NULL;

0 commit comments

Comments
 (0)