commit 7d89929c1ca0e2154767681965fa7965a28e0fcb
parent eba271280338864391feaf44c2cbf961d6215ea5
Author: cfillion <cfillion@users.noreply.github.com>
Date: Fri, 15 Sep 2017 16:37:11 -0400
api: don't allow adding a new repository without an URL with AddSetRepository
Diffstat:
3 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/api_repo.cpp b/src/api_repo.cpp
@@ -48,8 +48,7 @@ autoInstall: usually set to 2 (obey user setting).)",
try {
Remote remote = g_reapack->remote(name);
remote.setName(name);
- if(url && strlen(url) > 0)
- remote.setUrl(url);
+ remote.setUrl(url && strlen(url) > 0 ? url : remote.url());
remote.setEnabled(enable);
remote.setAutoInstall(boost::lexical_cast<tribool>(autoInstall));
g_reapack->addSetRemote(remote);
diff --git a/src/remote.cpp b/src/remote.cpp
@@ -114,7 +114,7 @@ void Remote::setUrl(const string &url)
{
if(!validateUrl(url))
throw reapack_error("invalid url");
- else if(m_protected)
+ else if(m_protected && url != m_url)
throw reapack_error("cannot change the URL of a protected repository");
else
m_url = url;
diff --git a/test/remote.cpp b/test/remote.cpp
@@ -153,6 +153,7 @@ TEST_CASE("null remote", M) {
TEST_CASE("protect remote", M) {
Remote remote;
+ remote.setUrl("https://cfillion.ca");
REQUIRE_FALSE(remote.isProtected());
remote.protect();
@@ -165,6 +166,8 @@ TEST_CASE("protect remote", M) {
catch(const reapack_error &e) {
REQUIRE(string(e.what()) == "cannot change the URL of a protected repository");
}
+
+ remote.setUrl(remote.url()); // this should work for AddSetRepository API
}
TEST_CASE("autoinstall remote", M) {