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

Skip to content

Commit ea5bf6b

Browse files
committed
treebuilder: don't try to verify submodules exist in the odb
Submodules don't exist in the objectdb and the code is making us try to look for a blob with its commit id, which is obviously not going to work. Skip the test if the user wants to insert a submodule.
1 parent 1609983 commit ea5bf6b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,8 @@ int git_treebuilder_insert(
757757
if (!valid_entry_name(bld->repo, filename))
758758
return tree_error("Failed to insert entry. Invalid name for a tree entry", filename);
759759

760-
if (!git_object__is_valid(bld->repo, id, otype_from_mode(filemode)))
760+
if (filemode != GIT_FILEMODE_COMMIT &&
761+
!git_object__is_valid(bld->repo, id, otype_from_mode(filemode)))
761762
return tree_error("Failed to insert entry; invalid object specified", filename);
762763

763764
pos = git_strmap_lookup_index(bld->map, filename);

tests/object/tree/write.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,25 @@ static void test_invalid_objects(bool should_allow_invalid)
490490
git_treebuilder_free(builder);
491491
}
492492

493+
static void test_inserting_submodule(void)
494+
{
495+
git_treebuilder *bld;
496+
git_oid sm_id;
497+
498+
cl_git_pass(git_treebuilder_new(&bld, g_repo, NULL));
499+
cl_git_pass(git_treebuilder_insert(NULL, bld, "sm", &sm_id, GIT_FILEMODE_COMMIT));
500+
git_treebuilder_free(bld);
501+
}
502+
493503
void test_object_tree_write__object_validity(void)
494504
{
495505
/* Ensure that we cannot add invalid objects by default */
496506
test_invalid_objects(false);
507+
test_inserting_submodule();
497508

498509
/* Ensure that we can turn off validation */
499510
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 0));
500511
test_invalid_objects(true);
512+
test_inserting_submodule();
501513
}
502514

0 commit comments

Comments
 (0)