Cog-Creators / Cog-Creators/Red-DiscordBot

Downloader gets stuck if `.git` exists but is invalid

Open
#6,580 4 comments 0 reactions 0 assignees View on GitHub
Category: Cogs - Downloader Status: Needs Discussion Type: Bug
Dominant language
Python
Stars
5.7k
Forks
2.5k
Avg merge
6d 16h
Merged PRs (30d)
1

Description

### Description
In order for `downloader._repo_manager._repos` to be filled with information about a repo, a number of initialization steps must take place. One of these is determining the remote URL for the repo, shown below:

https://github.com/Cog-Creators/Red-DiscordBot/blob/6603cd1a861230d36810b3889fe58c6dd48f9115/redbot/cogs/downloader/repo_manager.py#L787-L791

If this fails to happen, a warning is put in console and the folder is silently ignored:
`[2025-05-27 18:19:47] [WARNING] red.downloader: A remote URL does not exist for repo ...`
This can happen if the `.git` folder under `datapath/cogs/RepoManager/repos/.../.git` is empty or malformed.

Later, `[p]repo list` pulls from `downloader._repo_manager._repos` directly, so the repo fails to be listed. If a user then tries to `[p]repo add` to that repo name, they are told
`The repo name you provided is already in use. Please choose another name.`
This is because the `repo add` command logic uses a different method in `clone` to determine if the repo already exists:

https://github.com/Cog-Creators/Red-DiscordBot/blob/6603cd1a861230d36810b3889fe58c6dd48f9115/redbot/cogs/downloader/repo_manager.py#L187-L189

In this state, the user is unable to see the repo listed, is unable to use the repo to install cogs, and is unable to install the repo again to that name.
I'm not really sure what the best way to fix this problem is, but this does come up in #support with some frequency. The solution is usually to just delete the folder, but I'm not sure what effect that has on any already installed cogs.

### Reproduction
Reproduction is fairly easy, but it is unclear how something similar manages to happen in the wild. My best guess is that it has to do with improperly performed backup restorations freaking out Git when the paths change.
1. Add any repo with `[p]repo add`
2. Shut down the bot
3. Navigate to `datapath/cogs/RepoManager/repos//.git`
4. Delete the contents of the `.git` folder
5. Start up the bot
a. Notice the warning in console
b. Notice `[p]repo list` does not include the repo
c. Notice `[p]cog install` fails for that repo
d. Notice `[p]repo add` fails if attempted again

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.