Skip to content

Expose the repository directory ownership validation option #2036

Closed
@CyberSinh

Description

@CyberSinh

You can now disable the repository directory ownership validation by using the GIT_OPT_SET_OWNER_VALIDATION with git_libgit2_opts(): libgit2/libgit2#6266

This option is not yet exposed in the C# bindings, e.g. in the GlobalSettings static class.

Thanks.

Activity

kdlslyv

kdlslyv commented on Jun 10, 2023

@kdlslyv

Just opened a pull request for that.

For now you can do it like this:

    public static void DisableOwnershipCheckOpts()
    {
        CallNativeMethod("git_libgit2_opts", 36, 0);
    }

    public static void CallNativeMethod(string methodName, params object[] args)
    {
        Assembly libGit2SharpAssembly = typeof(LibGit2Sharp.Repository).GetTypeInfo().Assembly;
        Type proxyType = libGit2SharpAssembly.GetType("LibGit2Sharp.Core.NativeMethods")!;
        MethodInfo methodInfo = proxyType.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Static, new[] { typeof(int), typeof(int) })!;
        methodInfo.Invoke(null, args);
    }
CyberSinh

CyberSinh commented on Jun 11, 2023

@CyberSinh
Author

Thanks @kdlslyv for the pull request and the workaround. Hope your PR will be merged soon.
Another workaround avoiding reflection:

internal static partial class GlobalSettings2
{
   [LibraryImport("git2-e632535")]
   private static partial int git_libgit2_opts(int option, int enabled);

   public static void SetDirectoryOwnershipValidation(bool enable)
   {
      // https://github.com/libgit2/libgit2/blob/fc4c00b21983ddbe7a5e67e240c40fece4fea285/include/git2/common.h#L225
      const int GIT_OPT_SET_OWNER_VALIDATION = 36;

      // https://github.com/libgit2/libgit2/blob/fc4c00b21983ddbe7a5e67e240c40fece4fea285/include/git2/common.h#L487
      int enabled = enable ? 1 : 0;
      if (git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, enabled) < 0)
         throw new Exception($"git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, {enabled}) failed.");
   }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @CyberSinh@kdlslyv

      Issue actions

        Expose the repository directory ownership validation option · Issue #2036 · libgit2/libgit2sharp