Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4b0267

Browse files
Edward Thomsonethomson
Edward Thomson
authored andcommitted
submodule: reload HEAD/index after reading config
Reload the HEAD and index data for a submodule after reading the configuration. The configuration may specify a `path`, so we must update HEAD and index data with that path in mind.
1 parent 790012c commit f4b0267

File tree

1 file changed

+18
-24
lines changed

1 file changed

+18
-24
lines changed

src/submodule.c

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,6 @@ static int submodule_update_head(git_submodule *submodule)
14231423
return 0;
14241424
}
14251425

1426-
14271426
int git_submodule_reload(git_submodule *sm, int force)
14281427
{
14291428
int error = 0;
@@ -1433,35 +1432,30 @@ int git_submodule_reload(git_submodule *sm, int force)
14331432

14341433
assert(sm);
14351434

1436-
/* refresh index data */
1437-
if ((error = submodule_update_index(sm)) < 0)
1438-
return error;
1439-
1440-
/* refresh HEAD tree data */
1441-
if ((error = submodule_update_head(sm)) < 0)
1442-
return error;
1435+
if (!git_repository_is_bare(sm->repo)) {
1436+
/* refresh config data */
1437+
mods = gitmodules_snapshot(sm->repo);
1438+
if (mods != NULL) {
1439+
error = submodule_read_config(sm, mods);
1440+
git_config_free(mods);
14431441

1444-
/* done if bare */
1445-
if (git_repository_is_bare(sm->repo))
1446-
return error;
1442+
if (error < 0)
1443+
return error;
1444+
}
14471445

1448-
/* refresh config data */
1449-
mods = gitmodules_snapshot(sm->repo);
1450-
if (mods != NULL) {
1451-
error = submodule_read_config(sm, mods);
1452-
git_config_free(mods);
1446+
/* refresh wd data */
1447+
sm->flags &=
1448+
~(GIT_SUBMODULE_STATUS_IN_WD |
1449+
GIT_SUBMODULE_STATUS__WD_OID_VALID |
1450+
GIT_SUBMODULE_STATUS__WD_FLAGS);
14531451

1454-
if (error < 0) {
1455-
return error;
1456-
}
1452+
error = submodule_load_from_wd_lite(sm);
14571453
}
14581454

1459-
/* refresh wd data */
1460-
sm->flags &=
1461-
~(GIT_SUBMODULE_STATUS_IN_WD | GIT_SUBMODULE_STATUS__WD_OID_VALID |
1462-
GIT_SUBMODULE_STATUS__WD_FLAGS);
1455+
if (error == 0 && (error = submodule_update_index(sm)) == 0)
1456+
error = submodule_update_head(sm);
14631457

1464-
return submodule_load_from_wd_lite(sm);
1458+
return error;
14651459
}
14661460

14671461
static void submodule_copy_oid_maybe(

0 commit comments

Comments
 (0)