Skip to content

Introduce Remote.IsSupportedUrl() #754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions LibGit2Sharp.Tests/RemoteFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -304,5 +304,20 @@ public void CanNotRenameWhenRemoteWithSameNameExists()
Assert.Throws<NameConflictException>(() => repo.Network.Remotes.Rename("origin", "upstream"));
}
}

[Theory]
[InlineData("[email protected]:org/repo.git", false)]
[InlineData("git://site.com:80/org/repo.git", true)]
[InlineData("ssh://[email protected]:80/org/repo.git", false)]
[InlineData("http://site.com:80/org/repo.git", true)]
[InlineData("https://github.com:80/org/repo.git", true)]
[InlineData("ftp://site.com:80/org/repo.git", false)]
[InlineData("ftps://site.com:80/org/repo.git", false)]
[InlineData("file:///path/repo.git", true)]
[InlineData("protocol://blah.meh/whatever.git", false)]
public void CanCheckIfUrlisSupported(string url, bool supported)
{
Assert.Equal(supported, Remote.IsSupportedUrl(url));
}
}
}
6 changes: 6 additions & 0 deletions LibGit2Sharp/Core/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ internal delegate int git_remote_rename_problem_cb(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(LaxUtf8NoCleanupMarshaler))] string problematic_refspec,
IntPtr payload);


[DllImport(libgit2)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool git_remote_supported_url(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string url);

[DllImport(libgit2)]
internal static extern int git_branch_upstream_name(
GitBuf buf,
Expand Down
5 changes: 5 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2026,6 +2026,11 @@ public static string git_remote_url(RemoteSafeHandle remote)
return NativeMethods.git_remote_url(remote);
}

public static bool git_remote_supported_url(string url)
{
return NativeMethods.git_remote_supported_url(url);
}

#endregion

#region git_repository_
Expand Down
12 changes: 11 additions & 1 deletion LibGit2Sharp/Remote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,22 @@ internal string FetchSpecTransformToSource(string reference)
/// Determines if the proposed remote name is well-formed.
/// </summary>
/// <param name="name">The name to be checked.</param>
/// <returns>true is the name is valid; false otherwise.</returns>
/// <returns>true if the name is valid; false otherwise.</returns>
public static bool IsValidName(string name)
{
return Proxy.git_remote_is_valid_name(name);
}

/// <summary>
/// Determines if the proposed remote URL is supported by the library.
/// </summary>
/// <param name="url">The URL to be checked.</param>
/// <returns>true if the url is supported; false otherwise.</returns>
public static bool IsSupportedUrl(string url)
{
return Proxy.git_remote_supported_url(url);
}

/// <summary>
/// Determines whether the specified <see cref="Object"/> is equal to the current <see cref="Remote"/>.
/// </summary>
Expand Down