Skip to content

Conversation

@Jan200101
Copy link
Contributor

@Jan200101 Jan200101 commented Oct 2, 2021

Checks is the branch used for the repo exists using git show-ref --quiet --verify before trying to update

closes #3397

@github-actions github-actions bot added Category: Cogs - Downloader This is related to the Downloader cog. Category: Tests labels Oct 2, 2021
@Jackenmen
Copy link
Member

check if HEAD is detached

Can we just check if the given revision (which is saved in Config and therefore doesn't depend on the current, possibly invalid state of the repository) is a branch (I assume that is probably possible to do with git)? I think that's the only thing that isn't constant (and is therefore the only thing that Downloader can update)? Technically, tags can be modified too but I don't think we need to support it right now, especially that we don't even properly support when people force push to the branch.

@Jan200101
Copy link
Contributor Author

Jan200101 commented Oct 10, 2021

check if HEAD is detached

Can we just check if the given revision (which is saved in Config and therefore doesn't depend on the current, possibly invalid state of the repository) is a branch (I assume that is probably possible to do with git)? I think that's the only thing that isn't constant (and is therefore the only thing that Downloader can update)?

This sounds like a good idea but I am seeing one edge case, if the user manually updates the repo (for whatever reason) the commit in the config is no longer the latest commit of the branch.

I am unsure if this is something that needs to be tackled to prevent PEBKAC or if modifying red data outside of red is unsupported

Technically, tags can be modified too but I don't think we need to support it right now, especially that we don't even properly support when people force push to the branch.

.

@Jan200101
Copy link
Contributor Author

Jan200101 commented Oct 11, 2021

having had a bit to think about this, what about when a tag and branch are both on the same commit?
I think it would be better to generally look if the head is detached, which would leave branches entirely alone (unless there was an issue fast forwarding which would imply a force push or local change)

@Jackenmen
Copy link
Member

having had a bit to think about this, what about when a tag and branch are both on the same commit?

It probably doesn't matter. When you add a repo, you pass a named reference (or omit it, in which case the default branch is used and saved) which is saved with Config:

{
    "170708480":
    {
        "GLOBAL":
        {
            "repos":
            {
                "Fox-V3": "master",
                "aika": "v3",
                "preda": "master",
                "trusty": "master",
                "kenny": "v3-cogs",
                "jack-private": "v3",
                "draper": "master",
                "ax": "V3",
                "laggron": "v3",
                "PR4086": "master",
                "sinbad": "v3",
                "me-bounty": "main",
                "palmtree5": "redv3-rewrites",
                "weird": "master",
                "flame": "master"
            }
        }
    }
}

The current state of the repository doesn't really matter as we have the indication of whether we're dealing with a branch or something else based on this alone. We just need to detect whether the given name is a branch name which can be done by adding refs/heads/ (if it's not already there) and then verifying with git show-ref --verify.

@Jan200101 Jan200101 changed the title Check if branch is a tag before trying to update Check if branch exists before updating Oct 13, 2021
@Jan200101
Copy link
Contributor Author

right, ignore me forgetting to run black

I've changed the approach to the one you suggested: checking if the branch exists before updating.

This is implemented in a naive way and simply uses refs/heads/{branch} since I don't think the stored branch would ever be the full ref.

@Jan200101 Jan200101 marked this pull request as ready for review October 13, 2021 10:18
@Jan200101 Jan200101 requested a review from Jackenmen as a code owner October 13, 2021 10:18
@Jackenmen Jackenmen added hacktoberfest-accepted Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing. labels Oct 13, 2021
@Jackenmen Jackenmen added this to the 3.4.x milestone Dec 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category: Cogs - Downloader This is related to the Downloader cog. Type: Bug Unexpected behavior, result, or exception. In case of PRs, it is a fix for the foregoing.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Downloader] Repos set with tag as branch break [p]cog update

2 participants