pygit2
pygit2 copied to clipboard
pygit2 does not respect a global setting of safe.directory='*'
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.
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.
- add an
import pygit2statement to_init_.pyofdvcin your python environment - set the
OWNER_VALIDATIONoption of pygit2 to 0 in the same_init_.pyofdvc
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)
Related: libgit2/libgit2#6391?
@skshetry seems related to me yes. so therefore the problem lies in libgit2 and not even in pygit2?
@skshetry I just noticed that https://github.com/libgit2/libgit2/pull/6429 was merged in libgit2, which seems to be a duplicate of https://github.com/libgit2/libgit2/issues/6391
@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.
@skshetry I have tried pygit2==1.13.1 and confirmed this issue has gone.