libgit2 / libgit2sharp

Git + .NET = ❤
http://libgit2.github.com
MIT License
3.12k stars 878 forks source link

Exception: repository path not owned by current user #2039

Closed fellsoft closed 1 year ago

fellsoft commented 1 year ago

I have a Windows server application that runs as a system user (non-interactive, no home directory etc) that accesses a git repository using libgit2sharp. Code that was working with v0.26.2 breaks in v.0.27.0 & later.

The application breaks when creating a Repository object at this point:

using (Repository repo = new Repository(pathToRepo));

with exception:

LibGit2Sharp.LibGit2SharpException: repository path '[path]' is not owned by current user

Code works fine prior to v.027.0.

The process definitely has full access to the repository location (e.g. can write files).

I've seen various references to this error in relation to libgit (e.g. https://github.com/libgit2/libgit2/issues/6279)

They recommend adding a git config setting like this: [safe] directory = *

I've manually added this to the repository config file (.git\config) but the exception still occurs.

Am I missing something or is this a bug? Should I be adding the setting somewhere else, and if so, where (given this is a system user)?

fellsoft commented 1 year ago

After further testing & research, it seems the only way to get this setting recognised is to add it to the [ProgramFiles]\Git\etc\gitconfig file.

fellsoft commented 1 year ago

Further note: if git is not installed, the setting will be read from [ProgramData]\Git\config