Commit 55a7117d293c04f40fd943aeb141d856272070f6

Edward Thomson 2020-10-11T13:55:44

remote: use git_remote_name_is_valid

diff --git a/src/remote.c b/src/remote.c
index d471c4c..6ebdaf8 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -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)
 {
-	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_CONFIG,
 			"'%s' is not a valid remote name.", name ? name : "(null)");
diff --git a/tests/network/remote/isvalidname.c b/tests/network/remote/isvalidname.c
index c26fbd0..a3080f6 100644
--- a/tests/network/remote/isvalidname.c
+++ b/tests/network/remote/isvalidname.c
@@ -1,17 +1,24 @@
 #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)
 {
-	cl_assert_equal_i(false, git_remote_is_valid_name("/"));
-	cl_assert_equal_i(false, git_remote_is_valid_name("//"));
-	cl_assert_equal_i(false, git_remote_is_valid_name(".lock"));
-	cl_assert_equal_i(false, git_remote_is_valid_name("a.lock"));
-	cl_assert_equal_i(false, git_remote_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("/"));
+	cl_assert_equal_i(false, is_valid_name("//"));
+	cl_assert_equal_i(false, is_valid_name(".lock"));
+	cl_assert_equal_i(false, is_valid_name("a.lock"));
+	cl_assert_equal_i(false, is_valid_name("/no/leading/slash"));
+	cl_assert_equal_i(false, is_valid_name("no/trailing/slash/"));
 }
 
 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, git_remote_is_valid_name("yishaigalatzer/rules"));
+	cl_assert_equal_i(true, is_valid_name("webmatrix"));
+	cl_assert_equal_i(true, is_valid_name("yishaigalatzer/rules"));
 }