remote: Don't parse missing urls as empty strings
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
diff --git a/src/remote.c b/src/remote.c
index 948c755..4bba1d5 100644
--- a/src/remote.c
+++ b/src/remote.c
@@ -308,7 +308,7 @@ int git_remote_load(git_remote **out, git_repository *repo, const char *name)
if ((error = get_optional_config(config, &buf, NULL, (void *)&val)) < 0)
goto cleanup;
- if (val) {
+ if (val && strlen(val) > 0) {
remote->pushurl = git__strdup(val);
GITERR_CHECK_ALLOC(remote->pushurl);
}
diff --git a/tests-clar/network/remote/remotes.c b/tests-clar/network/remote/remotes.c
index dec6465..e356526 100644
--- a/tests-clar/network/remote/remotes.c
+++ b/tests-clar/network/remote/remotes.c
@@ -367,8 +367,14 @@ void test_network_remote_remotes__can_load_with_an_empty_url(void)
cl_git_pass(git_remote_load(&remote, _repo, "empty-remote-url"));
+ cl_assert(remote->url == NULL);
+ cl_assert(remote->pushurl == NULL);
+
cl_git_fail(git_remote_connect(remote, GIT_DIRECTION_FETCH));
+ cl_assert(giterr_last() != NULL);
+ cl_assert(giterr_last()->klass == GITERR_INVALID);
+
git_remote_free(remote);
}
diff --git a/tests-clar/resources/testrepo.git/config b/tests-clar/resources/testrepo.git/config
index 904a4e3..1264f6e 100644
--- a/tests-clar/resources/testrepo.git/config
+++ b/tests-clar/resources/testrepo.git/config
@@ -10,7 +10,7 @@
url = git://github.com/libgit2/libgit2
[remote "empty-remote-url"]
url =
-
+ pushurl =
[remote "test_with_pushurl"]
url = git://github.com/libgit2/fetchlibgit2
pushurl = git://github.com/libgit2/pushlibgit2