Skip to content

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

Open
@Flame442

Description

@Flame442

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:

git_command = ProcessFormatter().format(Repo.GIT_DISCOVER_REMOTE_URL, path=folder)
p = await self._run(git_command)
if p.returncode != 0:
raise errors.NoRemoteURL("Unable to discover a repo URL.", git_command)

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:

def _existing_git_repo(self) -> Tuple[bool, Path]:
git_path = self.folder_path / ".git"
return git_path.exists(), git_path

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Category: Cogs - DownloaderThis is related to the Downloader cog.Status: Needs DiscussionNeeds more discussion.Type: BugUnexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing.

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions