insert(name: str, oid: Oid, attr: FileMode)
Insert or replace an entry in the treebuilder.
Parameters:
attr
Available values are FileMode.BLOB, FileMode.BLOB_EXECUTABLE, FileMode.TREE, FileMode.LINK and FileMode.COMMIT.
Where is FileMode.BLOB defined?
import tempfile
import pygit2
import shutil
import sys
print(f"python: {sys.version}")
print(f"libgit2: {pygit2.LIBGIT2_VERSION}")
print(f"pygit2: {pygit2.__version__}")
repodir = tempfile.mkdtemp()
repo = pygit2.init_repository(repodir, bare=True)
sig = pygit2.Signature('Test User', 'testuser@nowhere.net')
data = 'blah blah master'
tree = repo.TreeBuilder()
data = repo.create_blob(data.encode())
try:
tree.insert('file', data, pygit2.FileMode.BLOB)
except Exception as e:
print(e)
try:
tree.insert('file', data, pygit2.TreeBuilder.FileMode.BLOB)
except Exception as e:
print(e)
shutil.rmtree(repodir)
python: 3.11.8 (main, Feb 29 2024, 12:19:47) [GCC]
libgit2: 1.8.0
pygit2: 1.14.1
module 'pygit2' has no attribute 'FileMode'
type object '_pygit2.TreeBuilder' has no attribute 'FileMode'
Documentation says:
Where is
FileMode.BLOB
defined?