Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

It's not documented how to use constants #1289

Open
hramrach opened this issue May 8, 2024 · 3 comments
Open

It's not documented how to use constants #1289

hramrach opened this issue May 8, 2024 · 3 comments

Comments

@hramrach
Copy link

hramrach commented May 8, 2024

Documentation says:

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', '[email protected]')

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'
@qaqland
Copy link

qaqland commented May 22, 2024

from pygit2 import enums

@hramrach
Copy link
Author

Yes, looking at the source I can understand this is required.

How am I supposed to infer that from the docs?

@siddhpant
Copy link

Bump

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants