Search code examples
c#.net-corelibgit2sharp

LibGit2Sharp Exception: repository path not owned by current user


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, the suggested fix for which is to add 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 with no $HOME directory)?


Solution

  • Answering my own question here, but on further research & testing I can get the

    [safe]
      directory = * 
    

    setting recognised only by adding it to either: C:\Program Files\git\etc\gitconfig file (if git is installed) or C:\ProgramData\Git\config (if git is not installed)