introduced new function: git_remote_supported_url() <-- returns true if this version of libgit2 supports the correct transport mechanism for a URL or path
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/src/transport.c b/src/transport.c
index e6ba075..cd1fd88 100644
--- a/src/transport.c
+++ b/src/transport.c
@@ -88,3 +88,9 @@ int git_remote_valid_url(const char *url)
return transport_find_fn(url) != NULL;
}
+int git_remote_supported_url(const char* url)
+{
+ git_transport_cb transport_fn = transport_find_fn(url);
+
+ return ((transport_fn != NULL) && (transport_fn != &git_transport_dummy));
+}
diff --git a/src/transport.h b/src/transport.h
index 4c12357..812099e 100644
--- a/src/transport.h
+++ b/src/transport.h
@@ -102,8 +102,20 @@ int git_transport_local(struct git_transport **transport);
int git_transport_git(struct git_transport **transport);
int git_transport_http(struct git_transport **transport);
int git_transport_dummy(struct git_transport **transport);
+
+/**
+ Returns true if the passed URL is valid (a URL with a Git supported scheme,
+ or pointing to an existing path)
+*/
int git_transport_valid_url(const char *url);
+/**
+ Returns true if the passed URL is supported by this version of libgit2.
+ (or, more technically, the transport method inferred by libgit is supported
+ by this version of libgit2).
+*/
+int git_remote_supported_url(const char* url);
+
typedef struct git_transport git_transport;
typedef int (*git_transport_cb)(git_transport **transport);
diff --git a/tests-clar/network/remotes.c b/tests-clar/network/remotes.c
index 4cf473d..add99c1 100644
--- a/tests-clar/network/remotes.c
+++ b/tests-clar/network/remotes.c
@@ -1,6 +1,7 @@
#include "clar_libgit2.h"
#include "buffer.h"
#include "refspec.h"
+#include "transport.h"
static git_remote *_remote;
static git_repository *_repo;
@@ -35,11 +36,21 @@ void test_network_remotes__parsing_ssh_remote(void)
cl_assert( git_remote_valid_url("git@github.com:libgit2/libgit2.git") );
}
-void test_network_remotes__parsing_local_path(void)
+void test_network_remotes__parsing_local_path_fails_if_path_not_found(void)
{
cl_assert( !git_remote_valid_url("/home/git/repos/libgit2.git") );
}
+void test_network_remotes__supported_transport_methods_are_supported(void)
+{
+ cl_assert( git_remote_supported_url("git://github.com/libgit2/libgit2") );
+}
+
+void test_network_remotes__unsupported_transport_methods_are_unsupported(void)
+{
+ cl_assert( !git_remote_supported_url("git@github.com:libgit2/libgit2.git") );
+}
+
void test_network_remotes__refspec_parsing(void)
{
cl_assert(!strcmp(git_refspec_src(_refspec), "refs/heads/*"));