Repository: Cog-Creators/Red-DiscordBot

Issue:
[V3 Downloader] Error when adding repo multiple times
# Command bugs

<!-- 
Did you find a bug with a command? Fill out the following:
-->

#### Command name

[p]repo add

#### What cog is this command from?

Downloader

#### What were you expecting to happen?

A message in Discord saying "That repo name you provided already exists. Please choose another."

#### What actually happened?

```
Exception in command 'repo add'
Traceback (most recent call last):
  File "/home/aikaterna/v3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 62, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "/home/aikaterna/v3/lib/python3.6/site-packages/redbot/cogs/downloader/downloader.py", line 228, in _repo_add
    repo = await self._repo_manager.add_repo(name=name, url=repo_url, branch=branch)
  File "/home/aikaterna/v3/lib/python3.6/site-packages/redbot/cogs/downloader/repo_manager.py", line 538, in add_repo
    "That repo name you provided already exists." " Please choose another."
redbot.cogs.downloader.errors.InvalidRepoName: That repo name you provided already exists. Please choose another.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/aikaterna/v3/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 886, in invoke
    yield from ctx.command.invoke(ctx)
  File "/home/aikaterna/v3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 927, in invoke
    yield from ctx.invoked_subcommand.invoke(ctx)
  File "/home/aikaterna/v3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 514, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/home/aikaterna/v3/lib/python3.6/site-packages/discord/ext/commands/core.py", line 71, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: InvalidRepoName: That repo name you provided already exists. Please choose another.
```

#### How can we reproduce this issue?

Add a repo, then add it again with the same name.



Discussion:
You didn't see the existing name message in discord at all?
The message in Discord was the standard "Error in command 'repo add'. Check your console or logs for details."

Resolving patch:
diff --git a/redbot/cogs/downloader/repo_manager.py b/redbot/cogs/downloader/repo_manager.py
--- a/redbot/cogs/downloader/repo_manager.py
+++ b/redbot/cogs/downloader/repo_manager.py
@@ -537,8 +537,8 @@ async def add_repo(self, url: str, name: str, branch: str = "master") -> Repo:
 
         """
         if self.does_repo_exist(name):
-            raise InvalidRepoName(
-                "That repo name you provided already exists." " Please choose another."
+            raise ExistingGitRepo(
+                "That repo name you provided already exists. Please choose another."
             )
 
         # noinspection PyTypeChecker


Test patch:
diff --git a/tests/cogs/downloader/test_downloader.py b/tests/cogs/downloader/test_downloader.py
--- a/tests/cogs/downloader/test_downloader.py
+++ b/tests/cogs/downloader/test_downloader.py
@@ -3,9 +3,11 @@
 from pathlib import Path
 
 import pytest
+from unittest.mock import MagicMock
 from raven.versioning import fetch_git_sha
 
 from redbot.cogs.downloader.repo_manager import RepoManager, Repo
+from redbot.cogs.downloader.errors import ExistingGitRepo
 
 
 async def fake_run(*args, **kwargs):
@@ -129,3 +131,13 @@ async def test_current_hash(bot_repo):
     sentry_sha = fetch_git_sha(str(bot_repo.folder_path))
 
     assert sentry_sha == commit
+
+
+@pytest.mark.asyncio
+async def test_existing_repo(repo_manager):
+    repo_manager.does_repo_exist = MagicMock(return_value=True)
+
+    with pytest.raises(ExistingGitRepo):
+        await repo_manager.add_repo("http://test.com", "test")
+
+    repo_manager.does_repo_exist.assert_called_once_with("test")