TreeDefinition treeDefinition = new TreeDefinition()
will create an empty TreeDefinition. As such, when you add a Blob to it, the eventually created Tree
will only contain one entry.
The TreeDefinition.From()
static helper method may help you here. It will allow one to create a TreeDefinition
from the actual content of an existing Commit
or Tree
.
Standard process would be to build a TreeDefinition
from a Commit
A, update the TreeDefinition
(by adding/removing entries from it), create a Tree
from it and eventually a new Commit
B which parent will be Commit
A.
You can take a peek at this test which show case this exact usage (Note: the test doesn't actually update the HEAD reference to make it point to the newly created commit, but your code does already tackle this).