diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2016-05-24 14:30:43 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2016-05-24 14:30:43 +0200 |
commit | a2cb47130ec7662811fe3447f69bae3f176e0362 (patch) | |
tree | 35413be2e32565798a07568f1bdcc60e12b35560 /src/tree.c | |
parent | c91a1dc1d975aa32c58cfafbf1625dcbb0be7c3c (diff) | |
download | libgit2-cmn/remove-single-entry.tar.gz |
tree: handle removal of all entries in the updatercmn/remove-single-entry
When we remove all entries in a tree, we should remove that tree from
its parent rather than include the empty tree.
Diffstat (limited to 'src/tree.c')
-rw-r--r-- | src/tree.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/tree.c b/src/tree.c index 4a9051cf8..43eefa50e 100644 --- a/src/tree.c +++ b/src/tree.c @@ -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); |