Commit 55a7117d by Edward Thomson

remote: use git_remote_name_is_valid

parent 023ebb9a
...@@ -82,9 +82,11 @@ static int download_tags_value(git_remote *remote, git_config *cfg) ...@@ -82,9 +82,11 @@ static int download_tags_value(git_remote *remote, git_config *cfg)
static int ensure_remote_name_is_valid(const char *name) static int ensure_remote_name_is_valid(const char *name)
{ {
int error = 0; int valid, error;
error = git_remote_name_is_valid(&valid, name);
if (!git_remote_is_valid_name(name)) { if (!error && !valid) {
git_error_set( git_error_set(
GIT_ERROR_CONFIG, GIT_ERROR_CONFIG,
"'%s' is not a valid remote name.", name ? name : "(null)"); "'%s' is not a valid remote name.", name ? name : "(null)");
......
#include "clar_libgit2.h" #include "clar_libgit2.h"
static int is_valid_name(const char *name)
{
int valid = 0;
cl_git_pass(git_remote_name_is_valid(&valid, name));
return valid;
}
void test_network_remote_isvalidname__can_detect_invalid_formats(void) void test_network_remote_isvalidname__can_detect_invalid_formats(void)
{ {
cl_assert_equal_i(false, git_remote_is_valid_name("/")); cl_assert_equal_i(false, is_valid_name("/"));
cl_assert_equal_i(false, git_remote_is_valid_name("//")); cl_assert_equal_i(false, is_valid_name("//"));
cl_assert_equal_i(false, git_remote_is_valid_name(".lock")); cl_assert_equal_i(false, is_valid_name(".lock"));
cl_assert_equal_i(false, git_remote_is_valid_name("a.lock")); cl_assert_equal_i(false, is_valid_name("a.lock"));
cl_assert_equal_i(false, git_remote_is_valid_name("/no/leading/slash")); cl_assert_equal_i(false, is_valid_name("/no/leading/slash"));
cl_assert_equal_i(false, git_remote_is_valid_name("no/trailing/slash/")); cl_assert_equal_i(false, is_valid_name("no/trailing/slash/"));
} }
void test_network_remote_isvalidname__wont_hopefully_choke_on_valid_formats(void) void test_network_remote_isvalidname__wont_hopefully_choke_on_valid_formats(void)
{ {
cl_assert_equal_i(true, git_remote_is_valid_name("webmatrix")); cl_assert_equal_i(true, is_valid_name("webmatrix"));
cl_assert_equal_i(true, git_remote_is_valid_name("yishaigalatzer/rules")); cl_assert_equal_i(true, is_valid_name("yishaigalatzer/rules"));
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment