private static string ConvertPath(Func <byte[], int> pathRetriever)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = pathRetriever(buffer);

            //TODO: Make libgit2 return different codes to clearly identify a not found file (GIT_ENOTFOUND ) from any other error (!= GIT_SUCCESS)
            if (result != (int)GitErrorCode.GIT_SUCCESS)
            {
                return(null);
            }

            return(Utf8Marshaler.Utf8FromBuffer(buffer));
        }
Example #2
0
        /// <summary>
        ///   Probe for a git repository.
        ///   <para>The lookup start from <paramref name = "startingPath" /> and walk upward parent directories if nothing has been found.</para>
        /// </summary>
        /// <param name = "startingPath">The base path where the lookup starts.</param>
        /// <returns>The path to the git repository.</returns>
        public static string Discover(string startingPath)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = NativeMethods.git_repository_discover(buffer, buffer.Length, PosixPathHelper.ToPosix(startingPath), false, null);

            if ((GitErrorCode)result == GitErrorCode.GIT_ENOTAREPO)
            {
                return(null);
            }

            Ensure.Success(result);

            return(PosixPathHelper.ToNative(Utf8Marshaler.Utf8FromBuffer(buffer)));
        }
Example #3
0
        private static string ConvertPath(Func <byte[], uint, int> pathRetriever)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = pathRetriever(buffer, NativeMethods.GIT_PATH_MAX);

            if (result == (int)GitErrorCode.GIT_ENOTFOUND)
            {
                return(null);
            }

            Ensure.Success(result);

            return(Utf8Marshaler.Utf8FromBuffer(buffer));
        }
Example #4
0
        /// <summary>
        ///   Probe for a git repository.
        ///   <para>The lookup start from <paramref name = "startingPath" /> and walk upward parent directories if nothing has been found.</para>
        /// </summary>
        /// <param name = "startingPath">The base path where the lookup starts.</param>
        /// <returns>The path to the git repository.</returns>
        public static string Discover(string startingPath)
        {
            var buffer = new byte[NativeMethods.GIT_PATH_MAX];

            int result = NativeMethods.git_repository_discover(buffer, buffer.Length, startingPath, false, null);

            if ((GitErrorCode)result == GitErrorCode.GIT_ENOTFOUND)
            {
                return(null);
            }

            Ensure.Success(result);

            FilePath discoveredPath = Utf8Marshaler.Utf8FromBuffer(buffer);

            return(discoveredPath.Native);
        }