NAME
Git::Native::TreeBuilder - Build a libgit2 tree object entry by entry
VERSION
version 0.005
SYNOPSIS
my $tb = $repo->tree_builder;
$tb->insert(name => 'hello.txt', oid => $blob_oid, mode => 0100644);
my $tree_oid = $tb->write;
DESCRIPTION
In-memory tree assembler. insert/remove mutate the builder; write persists it as a tree object and returns its OID.
Get one from "tree_builder" in Git::Native::Repository. It always starts empty — to amend an existing tree, insert its entries yourself from "entries" in Git::Native::Tree. Nothing reaches the object database until write.
insert
$tb->insert( name => 'hello.txt', oid => $blob_oid, mode => 0100644 );
$tb->insert( name => 'lib', oid => $tree_oid, mode => 040000 );
Add an entry, or replace the one already under that name. oid is a Git::Native::Oid or a 40-character hex string, name is a single path component (subdirectories are separate trees, inserted by their own OID), and mode is the numeric git filemode — 0100644 regular (the default), 0100755 executable, 0120000 symlink, 040000 subtree. Returns the builder, so calls chain.
remove
$tb->remove('hello.txt');
Drop the entry with that name from the builder. Returns the builder.
write
my $tree_oid = $tb->write;
Write the accumulated entries into the repository as a tree object and return its Git::Native::Oid. The builder stays usable afterwards; the result is the input for "commit_create" in Git::Native::Repository.
SEE ALSO
Git::Native::Tree, Git::Native::Repository
SUPPORT
Issues
Please report bugs and feature requests on GitHub at https://github.com/Getty/p5-git-native/issues.
CONTRIBUTING
Contributions are welcome! Please fork the repository and submit a pull request.
AUTHOR
Torsten Raudssus <getty@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2026 by Torsten Raudssus <torsten@raudssus.de> https://raudssus.de/.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.