Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
c756448c
Commit
c756448c
authored
May 24, 2016
by
Carlos Martín Nieto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3797 from libgit2/cmn/remove-single-entry
tree: handle removal of all entries in the updater
parents
c91a1dc1
a2cb4713
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
src/tree.c
+9
-0
tests/object/tree/update.c
+32
-0
No files found.
src/tree.c
View file @
c756448c
...
...
@@ -1093,6 +1093,15 @@ static int create_popped_tree(tree_stack_entry *current, tree_stack_entry *poppe
git_oid
new_tree
;
git_tree_free
(
popped
->
tree
);
/* If the tree would be empty, remove it from the one higher up */
if
(
git_treebuilder_entrycount
(
popped
->
bld
)
==
0
)
{
git_treebuilder_free
(
popped
->
bld
);
error
=
git_treebuilder_remove
(
current
->
bld
,
popped
->
name
);
git__free
(
popped
->
name
);
return
error
;
}
error
=
git_treebuilder_write
(
&
new_tree
,
popped
->
bld
);
git_treebuilder_free
(
popped
->
bld
);
...
...
tests/object/tree/update.c
View file @
c756448c
...
...
@@ -71,6 +71,38 @@ void test_object_tree_update__remove_blob_deeper(void)
git_tree_free
(
base_tree
);
}
void
test_object_tree_update__remove_all_entries
(
void
)
{
git_oid
tree_index_id
,
tree_updater_id
,
base_id
;
git_tree
*
base_tree
;
git_index
*
idx
;
const
char
*
path1
=
"subdir/subdir2/README"
;
const
char
*
path2
=
"subdir/subdir2/new.txt"
;
git_tree_update
updates
[]
=
{
{
GIT_TREE_UPDATE_REMOVE
,
{{
0
}},
GIT_FILEMODE_BLOB
/* ignored */
,
path1
},
{
GIT_TREE_UPDATE_REMOVE
,
{{
0
}},
GIT_FILEMODE_BLOB
/* ignored */
,
path2
},
};
cl_git_pass
(
git_oid_fromstr
(
&
base_id
,
"c4dc1555e4d4fa0e0c9c3fc46734c7c35b3ce90b"
));
cl_git_pass
(
git_tree_lookup
(
&
base_tree
,
g_repo
,
&
base_id
));
/* Create it with an index */
cl_git_pass
(
git_index_new
(
&
idx
));
cl_git_pass
(
git_index_read_tree
(
idx
,
base_tree
));
cl_git_pass
(
git_index_remove
(
idx
,
path1
,
0
));
cl_git_pass
(
git_index_remove
(
idx
,
path2
,
0
));
cl_git_pass
(
git_index_write_tree_to
(
&
tree_index_id
,
idx
,
g_repo
));
git_index_free
(
idx
);
/* Perform the same operation via the tree updater */
cl_git_pass
(
git_tree_create_updated
(
&
tree_updater_id
,
g_repo
,
base_tree
,
2
,
updates
));
cl_assert_equal_oid
(
&
tree_index_id
,
&
tree_updater_id
);
git_tree_free
(
base_tree
);
}
void
test_object_tree_update__replace_blob
(
void
)
{
git_oid
tree_index_id
,
tree_updater_id
,
base_id
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment