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

Port the GIT_OPT_GET_OWNER_VALIDATION option to Python #1150

Merged
merged 3 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ build_script:
# Clone, build and install libgit2
- cmd: |
set LIBGIT2=%APPVEYOR_BUILD_FOLDER%\venv
git clone --depth=1 -b v1.4.2 https://github.com/libgit2/libgit2.git libgit2
git clone --depth=1 -b v1.4.3 https://github.com/libgit2/libgit2.git libgit2
cd libgit2
cmake . -DBUILD_TESTS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="%LIBGIT2%" -G "%GENERATOR%"
cmake --build . --target install
Expand Down
2 changes: 1 addition & 1 deletion docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ Python requirements (these are specified in ``setup.py``):
- cffi 1.9.1+
- cached-property

Libgit2 **v1.4.x**; binary wheels already include libgit2, so you only need to
Libgit2 **v1.4.3+**; binary wheels already include libgit2, so you only need to
worry about this if you install the source package.

Optional libgit2 dependecies to support ssh and https:
Expand Down
13 changes: 13 additions & 0 deletions src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ option(PyObject *self, PyObject *args)
case GIT_OPT_ENABLE_STRICT_HASH_VERIFICATION:
case GIT_OPT_ENABLE_UNSAVED_INDEX_SAFETY:
case GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS:
case GIT_OPT_SET_OWNER_VALIDATION:
{
PyObject *py_enabled;
int enabled;
Expand All @@ -317,6 +318,18 @@ option(PyObject *self, PyObject *args)
Py_RETURN_NONE;
}

// int enabled getter
case GIT_OPT_GET_OWNER_VALIDATION:
{
int enabled;

error = git_libgit2_opts(option, &enabled);
if (error < 0)
return Error_set(error);

return PyLong_FromLong(enabled);
}

// Not implemented
case GIT_OPT_SET_SSL_CIPHERS:
case GIT_OPT_GET_USER_AGENT:
Expand Down
7 changes: 7 additions & 0 deletions src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ PyDoc_STRVAR(option__doc__,
"\n"
"GIT_OPT_SET_MWINDOW_SIZE, size\n"
" Set the maximum mmap window size.\n"
"\n"
"GIT_OPT_GET_OWNER_VALIDATION\n"
" Gets the owner validation setting for repository directories.\n"
"\n"
"GIT_OPT_SET_OWNER_VALIDATION, enabled\n"
" Set that repository directories should be owned by the current user.\n"
" The default is to validate ownership.\n"
);


Expand Down
2 changes: 2 additions & 0 deletions src/pygit2.c
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,8 @@ PyInit__pygit2(void)
ADD_CONSTANT_INT(m, GIT_OPT_GET_PACK_MAX_OBJECTS);
ADD_CONSTANT_INT(m, GIT_OPT_SET_PACK_MAX_OBJECTS);
ADD_CONSTANT_INT(m, GIT_OPT_DISABLE_PACK_KEEP_FILE_CHECKS);
ADD_CONSTANT_INT(m, GIT_OPT_GET_OWNER_VALIDATION);
ADD_CONSTANT_INT(m, GIT_OPT_SET_OWNER_VALIDATION);

/* Exceptions */
ADD_EXC(m, GitError, NULL);
Expand Down
4 changes: 4 additions & 0 deletions test/test_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,7 @@ def test_search_path_proxy():
for level, path in paths:
pygit2.settings.search_path[level] = path
assert path == pygit2.settings.search_path[level]

def test_owner_validation():
__option(pygit2.GIT_OPT_GET_OWNER_VALIDATION,
pygit2.GIT_OPT_SET_OWNER_VALIDATION, 0)