Skip to content

Commit

Permalink
fix git_treebuilder_insert probrem.
Browse files Browse the repository at this point in the history
couldn't add new entry when inserting new one with `git_treebuilder_insert`.
  • Loading branch information
chobie authored and vmg committed Apr 8, 2011
1 parent 5868cd0 commit 98ac678
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, con
git_oid_cpy(&entry->oid, id);
entry->attr = attributes;

if (pos != GIT_ENOTFOUND) {
if (pos == GIT_ENOTFOUND) {
if (git_vector_insert(&bld->entries, entry) < 0)
return GIT_ENOMEM;
}
Expand Down
29 changes: 29 additions & 0 deletions tests/t09-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd";

static const char *blob_oid = "fa49b077972391ad58037050f2a75f74e3671e92";
static const char *first_tree = "181037049a54a1eb5fab404658a3a250b44335d7";
static const char *second_tree = "f60079018b664e4e79329a7ef9559c8d9e0378d1";

#if 0
static int print_tree(git_repository *repo, const git_oid *tree_oid, int depth)
{
Expand Down Expand Up @@ -126,11 +130,36 @@ BEGIN_TEST(write0, "write a tree from an index")
END_TEST
#endif

BEGIN_TEST(write2, "write a tree from a memory")
git_repository *repo;
git_index *index;
git_treebuilder *builder;
git_tree *tree;
git_oid id;
git_oid bid;
git_oid rid;

must_pass(git_repository_open(&repo, REPOSITORY_FOLDER));
git_oid_mkstr(&id, first_tree);
git_oid_mkstr(&bid, blob_oid);

//create a second tree from first tree using `git_treebuilder_insert` on REPOSITORY_FOLDER.
must_pass(git_tree_lookup(&tree, repo, &id));
must_pass(git_treebuilder_create(&builder, tree));
must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644));
must_pass(git_treebuilder_write(&rid,repo,builder));

char out[41];
git_oid_to_string(out,41,&rid);
must_pass(strcmp(out,second_tree));
END_TEST

BEGIN_SUITE(tree)
//ADD_TEST(print0);
ADD_TEST(read0);
ADD_TEST(read1);
//ADD_TEST(write0);
//ADD_TEST(write1);
ADD_TEST(write2);
END_SUITE

0 comments on commit 98ac678

Please sign in to comment.