Merge pull request #3653 from libgit2/cmn/treebuilder-submodule treebuilder: don't try to verify submodules exist in the odb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
diff --git a/src/tree.c b/src/tree.c
index 2c31515..48b9f12 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -757,7 +757,8 @@ int git_treebuilder_insert(
if (!valid_entry_name(bld->repo, filename))
return tree_error("Failed to insert entry. Invalid name for a tree entry", filename);
- if (!git_object__is_valid(bld->repo, id, otype_from_mode(filemode)))
+ if (filemode != GIT_FILEMODE_COMMIT &&
+ !git_object__is_valid(bld->repo, id, otype_from_mode(filemode)))
return tree_error("Failed to insert entry; invalid object specified", filename);
pos = git_strmap_lookup_index(bld->map, filename);
diff --git a/tests/object/tree/write.c b/tests/object/tree/write.c
index 341f5db..a9decf9 100644
--- a/tests/object/tree/write.c
+++ b/tests/object/tree/write.c
@@ -490,13 +490,25 @@ static void test_invalid_objects(bool should_allow_invalid)
git_treebuilder_free(builder);
}
+static void test_inserting_submodule(void)
+{
+ git_treebuilder *bld;
+ git_oid sm_id;
+
+ cl_git_pass(git_treebuilder_new(&bld, g_repo, NULL));
+ cl_git_pass(git_treebuilder_insert(NULL, bld, "sm", &sm_id, GIT_FILEMODE_COMMIT));
+ git_treebuilder_free(bld);
+}
+
void test_object_tree_write__object_validity(void)
{
/* Ensure that we cannot add invalid objects by default */
test_invalid_objects(false);
+ test_inserting_submodule();
/* Ensure that we can turn off validation */
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0));
test_invalid_objects(true);
+ test_inserting_submodule();
}