8000 pygit2 does not respect a global setting of safe.directory='*' · Issue #1156 · libgit2/pygit2 · GitHub
[go: up one dir, main page]

Skip to content

pygit2 does not respect a global setting of safe.directory='*' #1156

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

Open
onew4y opened this issue Aug 16, 2022 · 7 comments
Open

pygit2 does not respect a global setting of safe.directory='*' #1156

onew4y opened this issue Aug 16, 2022 · 7 comments

Comments

@onew4y
Copy link
onew4y commented Aug 16, 2022

We are currently working with dvc for multiple projects and the dvc exp run leads to a pygit2 exception on a azure machine learning instance. This leads to problems since folders on mounted drives in azure belong to user root whilst the working user is azureuser The exception looks like following:

_pygit2.GitError: /mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>/.git/: repository path '/mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>' is not owned by current user

A workaround for this problem should be setting the git safe.directory to ='*'.
But unfortunately this does not work with dvc resp. pygit2.

I narrowed the problem down and was able to reproduce it with pure pygit2.
Since it seems to be a pygit2 problem, I am opening the issue directly here.
FYI @efiop, @skshetry, @dmpetrov

My git config looks as follows:

user.email=<XXX>
user.name=<XXX>
safe.directory=*

With my normal git (git version 2.36.1) everything works great with the wildcard *. But pygit2 seems to ignore this config.

import pygit2
repo = pygit2.Repository(pygit2.discover_repository('.'))
GitError: /mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>/.git: repository path '/mnt/batch/tasks/shared/LS_root/mounts/clusters/<XXX>/' is not owned by current user

But the config seems to be loaded:

import pygit2
config = pygit2.Config()
for x in config.get_global_config():
    print(x.name + ":" + x.value)
user.email:<XXX>
user.name:<XXX>
safe.directory:*

Used Versions: pygit2 1.10.0

Any help would be really appreciated, since we can't run experiments anymore.

@meierale
Copy link
meierale commented Aug 25, 2022

Thanks to @onew4y there seems to be a workaround for dvc ... but it's more of a dirty hack than a way to proceed with this.

8000
  1. add an import pygit2 statement to _init_.py of dvc in your python environment
  2. set the OWNER_VALIDATION option of pygit2 to 0 in the same _init_.py of dvc

Here's how it can be done when working with conda:

echo "import pygit2" >> /anaconda/envs/$(ENV_NAME)/lib/python3.8/site-packages/dvc/_init_.py
echo "pygit2.option(pygit2.GIT_OPT_SET_OWNER_VALIDATION, 0)" >> /anaconda/envs/$(ENV_NAME)/lib/python3.8/site-packages/dvc/_init_.py

It is unclear why the global safe.directory setting of git is not taken into account and has to be set individually as pygit2.option. We still believe this is a pygit2 issue, not a dvc issue.
(FYI @efiop)

@skshetry
Copy link
Contributor

Related: libgit2/libgit2#6391?

@onew4y
Copy link
Author
onew4y commented Aug 25, 2022

@skshetry seems related to me yes. so therefore the problem lies in libgit2 and not even in pygit2?

@meierale
Copy link

@skshetry I just noticed that libgit2/libgit2#6429 was merged in libgit2, which seems to be a duplicate of libgit2/libgit2#6391

< AFAD div class="TimelineItem js-comment-container" data-gid="IC_kwDOABA1Xc5aRxxl" data-url="/libgit2/pygit2/comments/IC_kwDOABA1Xc5aRxxl/partials/timeline_issue_comment" >
@skshetry
Copy link
Contributor

@meierale @onew4y, could you please check if this works with pygit2==1.12.0? Looks like this was fixed in libgit2>=1.6.1 which is used in latest pygit2 release.

@Magentaize
Copy link

@skshetry I have tried pygit2==1.13.1 and confirmed this issue has gone.

@jiachenhan
Copy link

pygit2==1.13.0
I noticed that if git does not exist in the environment, this problem XX is not owned by current user
seems to occur.
However, after installing git, and running git config -- global -- add safe. directory '*' this problem seems to be resolved.

So it's not a pure pygit2 issue

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

5 participants
0