8000 Introduce Remote.IsSupportedUrl. · apfunk/libgit2sharp@9fbeaac · GitHub
[go: up one dir, main page]

Skip to content

Commit 9fbeaac

Browse files
committed
Introduce Remote.IsSupportedUrl.
1 parent ed3eda0 commit 9fbeaac

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

LibGit2Sharp.Tests/RemoteFixture.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,5 +304,20 @@ public void CanNotRenameWhenRemoteWithSameNameExists()
304304
Assert.Throws<NameConflictException>(() => repo.Network.Remotes.Rename("origin", "upstream"));
305305
}
306306
}
307+
308+
[Theory]
309+
[InlineData("git@github.com:org/repo.git", false)]
310+
[InlineData("git://site.com:80/org/repo.git", true)]
311+
[InlineData("ssh://user@host.com:80/org/repo.git", false)]
312+
[InlineData("http://site.com:80/org/repo.git", true)]
313+
[InlineData("https://github.com:80/org/repo.git", true)]
314+
[InlineData("ftp://site.com:80/org/repo.git", false)]
315+
[InlineData("ftps://site.com:80/org/repo.git", false)]
316+
[InlineData("file:///path/repo.git", true)]
317+
[InlineData("protocol://blah.meh/whatever.git", false)]
318+
public void CanCheckIfUrlisSupported(string url, bool supported)
319+
{
320+
Assert.Equal(supported, Remote.IsSupportedUrl(url));
321+
}
307322
}
308323
}

LibGit2Sharp/Core/NativeMethods.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ internal delegate int git_remote_rename_problem_cb(
223223
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] string problematic_refspec,
224224
IntPtr payload);
225225

226+
227+
[DllImport(libgit2)]
228+
[return: MarshalAs(UnmanagedType.Bool)]
229+
internal static extern bool git_remote_supported_url(
230+
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);
231+
226232
[DllImport(libgit2)]
227233
internal static extern int git_branch_upstream_name(
228234
GitBuf buf,

LibGit2Sharp/Core/Proxy.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,11 @@ public static string git_remote_url(RemoteSafeHandle remote)
20262026
return NativeMethods.git_remote_url(remote);
20272027
}
20282028

2029+
public static bool git_remote_supported_url(string url)
2030+
{
2031+
return NativeMethods.git_remote_supported_url(url);
2032+
}
2033+
20292034
#endregion
20302035

20312036
#region git_repository_

LibGit2Sharp/Remote.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,22 @@ internal string FetchSpecTransformToSource(string reference)
9999
/// Determines if the proposed remote name is well-formed.
100100
/// </summary>
101101
/// <param name="name">The name to be checked.</param>
102-
/// <returns>true is the name is valid; false otherwise.</returns>
102+
/// <returns>true if the name is valid; false otherwise.</returns>
103103
public static bool IsValidName(string name)
104104
{
105105
return Proxy.git_remote_is_valid_name(name);
106106
}
107107

108+
/// <summary>
109+
/// Determines if the proposed remote URL is supported by the library.
110+
/// </summary>
111+
/// <param name="url">The URL to be checked.</param>
112+
/// <returns>true if the url is supported; false otherwise.</returns>
113+
public static bool IsSupportedUrl(string url)
114+
{
115+
return Proxy.git_remote_supported_url(url);
116+
}
117+
108118
/// <summary>
109119
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Remote"/>.
110120
/// </summary>

0 commit comments

Comments
 (0)
0