summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2017-03-14 14:53:32 +0100
committerPatrick Steinhardt <ps@pks.im>2017-03-14 14:53:32 +0100
commit32ecc98e51ab73a7db49dfb178ea670e6f68321b (patch)
tree0b3b0d41ffd5769848434e76bd6bde53ffe309a8
parent53454be87f9b14f5df79a5917ce3986590438748 (diff)
downloadlibgit2-32ecc98e51ab73a7db49dfb178ea670e6f68321b.tar.gz
submodule: catch when submodule is not staged on update
When calling `git_submodule_update` on a submodule, we have to retrieve the ID of the submodule entry in the index. If the function is called on a submodule which is only partly initialized, the submodule entry may not be added to the index yet. This leads to an assert when trying to look up the blob later on. Fix the issue by checking if the index actually holds the submodule's ID and erroring out if it does not.
-rw-r--r--src/submodule.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/submodule.c b/src/submodule.c
index 095bbb090..191cdf3dd 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1212,6 +1212,8 @@ int git_submodule_update(git_submodule *sm, int init, git_submodule_update_optio
(error = git_checkout_head(sub_repo, &update_options.checkout_opts)) != 0)
goto done;
} else {
+ const git_oid *oid;
+
/**
* Work dir is initialized - look up the commit in the parent repository's index,
* 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
if ((error = git_submodule_open(&sub_repo, sm)) < 0)
goto done;
+ if ((oid = git_submodule_index_id(sm)) == NULL) {
+ giterr_set(GITERR_SUBMODULE, "could not get ID of submodule in index");
+ error = -1;
+ goto done;
+ }
+
/* Look up the target commit in the submodule. */
- if ((error = git_object_lookup(&target_commit, sub_repo, git_submodule_index_id(sm), GIT_OBJ_COMMIT)) < 0) {
+ if ((error = git_object_lookup(&target_commit, sub_repo, oid, GIT_OBJ_COMMIT)) < 0) {
/* If it isn't found then fetch and try again. */
if (error != GIT_ENOTFOUND || !update_options.allow_fetch ||
(error = lookup_default_remote(&remote, sub_repo)) < 0 ||