commit a0b5a2665315026dfba83dda85e4f7367c3fb2d9
parent 49b8ddd0a74f4370bfaa0a0b9fc7fa49b6d46413
Author: cfillion <cfillion@users.noreply.github.com>
Date: Mon, 15 Feb 2016 15:16:48 -0500
fix corruption of the remote list after uninstallation
Diffstat:
2 files changed, 26 insertions(+), 3 deletions(-)
diff --git a/src/remote.cpp b/src/remote.cpp
@@ -185,10 +185,17 @@ void RemoteList::remove(const string &name)
{
const auto it = m_map.find(name);
- if(it != m_map.end()) {
- m_remotes.erase(m_remotes.begin() + it->second);
- m_map.erase(it);
+ if(it == m_map.end())
+ return;
+
+ m_remotes.erase(m_remotes.begin() + it->second);
+
+ for(auto walk = m_map.begin(); walk != m_map.end(); walk++) {
+ if(walk->second > it->second)
+ walk->second--;
}
+
+ m_map.erase(it);
}
Remote RemoteList::get(const string &name) const
diff --git a/test/remote.cpp b/test/remote.cpp
@@ -306,6 +306,22 @@ TEST_CASE("remove remote", M) {
list.remove("world"); // no crash
}
+TEST_CASE("remove two remotes", M) {
+ RemoteList list;
+
+ list.add({"a_first", "url"});
+ list.add({"z_second", "url"});
+ list.add({"b_third", "url"});
+ REQUIRE(list.size() == 3);
+
+ list.remove("z_second");
+ REQUIRE(list.size() == 2);
+
+ REQUIRE(list.get("z_first").isNull());
+ REQUIRE_FALSE(list.get("b_third").isNull());
+ REQUIRE_FALSE(list.get("a_first").isNull());
+}
+
TEST_CASE("compare remotes", M) {
REQUIRE(Remote("a", "a") < Remote("b", "a"));
REQUIRE_FALSE(Remote("a", "a") < Remote("a", "b"));