Downloader gets stuck if .git exists but is invalid #6580

Closed
opened 2025-05-28 00:42:34 +02:00 by Flame442 · 5 comments
Flame442 commented 2025-05-28 00:42:34 +02:00 (Migrated from github.com)

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:

github.com/Cog-Creators/Red-DiscordBot@6603cd1a86/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:

github.com/Cog-Creators/Red-DiscordBot@6603cd1a86/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/<the repo you added>/.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
### 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/<the repo you added>/.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
Biotr commented 2025-06-02 12:51:36 +02:00 (Migrated from github.com)

I'm thinking about how to handle this issue and have a few ideas.

One approach is to attempt re-cloning the repository:

  • When the .git directory is malformed but the .git/config file still exists, the remote URL can be extracted and used to re-clone the repository.
  • Another option I thought of is to store the repository URL somewhere (if it's not stored already) and use it to re-clone the repository.

If none of these options help, then throw an error and delete the directory, so the user can repo add again.

I'm thinking about how to handle this issue and have a few ideas. One approach is to attempt re-cloning the repository: - When the `.git` directory is malformed but the `.git/config` file still exists, the remote URL can be extracted and used to re-clone the repository. - Another option I thought of is to store the repository URL somewhere (if it's not stored already) and use it to re-clone the repository. If none of these options help, then throw an error and delete the directory, so the user can `repo add` again.
qingshen0000 commented 2025-11-07 02:56:19 +01:00 (Migrated from github.com)

Hello! I’m currently working on a school project focused on contributing to open source. I was wondering if I could take on this issue. Thank you!

Hello! I’m currently working on a school project focused on contributing to open source. I was wondering if I could take on this issue. Thank you!
Flame442 commented 2025-11-07 03:18:36 +01:00 (Migrated from github.com)

You may, but this issue hasn't had a specific solution defined yet so it may not be the best one to take. You may want to join our discord at https://discord.gg/red if you plan on contributing.

You may, but this issue hasn't had a specific solution defined yet so it may not be the best one to take. You may want to join our discord at https://discord.gg/red if you plan on contributing.
qingshen0000 commented 2025-11-07 04:06:35 +01:00 (Migrated from github.com)

You may, but this issue hasn't had a specific solution defined yet so it may not be the best one to take. You may want to join our discord at https://discord.gg/red if you plan on contributing.

Thanks! I'll also take a look at other issues!

> You may, but this issue hasn't had a specific solution defined yet so it may not be the best one to take. You may want to join our discord at https://discord.gg/red if you plan on contributing. Thanks! I'll also take a look at other issues!
Owner

Behoben in e96eefd27: [p]repo list listet Repo-Ordner, die nicht geladen werden konnten, bereits auf. [p]repo add erklärt jetzt in diesem Fall, dass ein Ordner mit dem Namen existiert, aber kaputt ist, und dass man ihn aus dem Repos-Ordner (Pfad wird angezeigt) entfernen und das Repo neu hinzufügen kann.


Generated by Claude Code

Behoben in e96eefd27: `[p]repo list` listet Repo-Ordner, die nicht geladen werden konnten, bereits auf. `[p]repo add` erklärt jetzt in diesem Fall, dass ein Ordner mit dem Namen existiert, aber kaputt ist, und dass man ihn aus dem Repos-Ordner (Pfad wird angezeigt) entfernen und das Repo neu hinzufügen kann. --- _Generated by [Claude Code](https://claude.ai/code)_
Sign in to join this conversation.
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#6580
No description provided.