Skip to main content

trees

Creates, updates, deletes, gets or lists a trees resource.

Overview

Nametrees
TypeResource
Idgithub.git.trees

Fields

The following fields are returned by SELECT queries:

Response

NameDatatypeDescription
shastring
treearrayObjects specifying a tree structure
truncatedboolean
urlstring (uri)

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
get_treeselectowner, repo, tree_sharecursiveReturns a single tree using the SHA1 value or ref name for that tree.

If truncated is true in the response then the number of items in the tree array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.

> [!NOTE]
> The limit for the tree array is 100,000 entries with a maximum size of 7 MB when using the recursive parameter.
create_treeinsertowner, repo, treeThe tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.

If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see "Create a commit" and "Update a reference."

Returns an error if you try to delete a file that does not exist.

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
ownerstringThe account owner of the repository. The name is not case sensitive.
repostringThe name of the repository without the .git extension. The name is not case sensitive.
tree_shastringThe SHA1 value or ref (branch or tag) name of the tree.
recursivestringSetting this parameter to any value returns the objects or subtrees referenced by the tree specified in :tree_sha. For example, setting recursive to any of the following will enable returning objects or subtrees: 0, 1, "true", and "false". Omit this parameter to prevent recursively returning objects or subtrees.

SELECT examples

Returns a single tree using the SHA1 value or ref name for that tree.

If truncated is true in the response then the number of items in the tree array exceeded our maximum limit. If you need to fetch more items, use the non-recursive method of fetching trees, and fetch one sub-tree at a time.

> [!NOTE]
> The limit for the tree array is 100,000 entries with a maximum size of 7 MB when using the recursive parameter.

SELECT
sha,
tree,
truncated,
url
FROM github.git.trees
WHERE owner = '{{ owner }}' -- required
AND repo = '{{ repo }}' -- required
AND tree_sha = '{{ tree_sha }}' -- required
AND recursive = '{{ recursive }}'
;

INSERT examples

The tree creation API accepts nested entries. If you specify both a tree and a nested path modifying that tree, this endpoint will overwrite the contents of the tree with the new path contents, and create a new tree structure.

If you use this endpoint to add, delete, or modify the file contents in a tree, you will need to commit the tree and then update a branch to point to the commit. For more information see "Create a commit" and "Update a reference."

Returns an error if you try to delete a file that does not exist.

INSERT INTO github.git.trees (
tree,
base_tree,
owner,
repo
)
SELECT
'{{ tree }}' /* required */,
'{{ base_tree }}',
'{{ owner }}',
'{{ repo }}'
RETURNING
sha,
tree,
truncated,
url
;