Skip to content

Commit 6dfb983

Browse files
authored
Merge pull request libgit2#4161 from pks-t/pks/submodule-index-fix
submodule: catch when submodule is not staged on update
2 parents 8051b47 + 32ecc98 commit 6dfb983

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/submodule.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,8 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
12121212
(error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0)
12131213
goto done;
12141214
} else {
1215+
const git_oid *oid;
1216+
12151217
/**
12161218
* Work dir is initialized - look up the commit in the parent repository's index,
12171219
* update the workdir contents of the subrepository, and set the subrepository's
@@ -1220,8 +1222,14 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
12201222
if ((error = git_submodule_open(&sub_repo, sm)) < 0)
12211223
goto done;
12221224

1225+
if ((oid = git_submodule_index_id(sm)) == NULL) {
1226+
giterr_set(GITERR_SUBMODULE, "could not get ID of submodule in index");
1227+
error = -1;
1228+
goto done;
1229+
}
1230+
12231231
/* Look up the target commit in the submodule. */
1224-
if ((error = git_object_lookup(&target_commit, sub_repo, git_submodule_index_id(sm), GIT_OBJ_COMMIT)) < 0) {
1232+
if ((error = git_object_lookup(&target_commit, sub_repo, oid, GIT_OBJ_COMMIT)) < 0) {
12251233
/* If it isn't found then fetch and try again. */
12261234
if (error != GIT_ENOTFOUND || !update_options.allow_fetch ||
12271235
(error = lookup_default_remote(&remote, sub_repo)) < 0 ||

0 commit comments

Comments
 (0)