Skip to content

Prevent PR refs being deleted by git push --mirror #18174

Closed
@xyzroller

Description

@xyzroller

Feature Description

What am I trying to achieve?

My project's "source-of-truth" repositories are on one Gitea server and I would like to mirror them to another Gitea server to enable collaboration there.

E.g., my primary "source of truth" repositories are on a self-hosted Gitea instance and I would like to enable collaboration on Codeberg.

To do this, I add a post-receive GitHook to the primary ("source-of-truth") repository to git push --mirror to the secondary repository.

What's the problem?

When a PR is submitted on the secondary, my workflow on my local machine is to 1) pull main from the primary, 2) check out a new feature branch, 3) pull from the contributor's fork feature branch, 4) merge the feature branch to main and then 5) push main to the primary.

The primary then push mirrors to the secondary and the PR on the secondary is broken and gives a 500 error.

The PR seems to break because mirroring the primary repository to the secondary deletes the refs for the PR on the secondary - the refs aren't present on the primary repo and are therefore deleted when git push --mirror is executed -- see "...deleted refs will be removed from the remote end" in the git-push --mirror docs here

Feature Request - How could/should it work?

The workflow above is working:

  • when the PR is on the primary
  • when the secondary is a GitHub mirror. Probably because "The remote refs/pull/ namespace is read-only" -- see here -- so that the PR refs on GitHub are not deleted when git push --mirror executes on the primary.

In both of these cases, merging a PR feature branch locally leads to the PR being automatically recognised as "manually merged" <-- this is what I am ultimately trying to achieve on a Gitea mirror.

With a Gitea secondary, if instead of using git push --mirror on the primary repository post-receive Git Hook, I use git push --all followed by git push --prune, then the merge on the primary is pushed to the secondary without deleting the PR refs and the PR on the secondary is automatically detected as "manually merged", which is what I want to happen. However, mirroring would be preferred.

So the feature request is: Make PR refs read-only (as GitHub does) so that mirroring does not break PRs on a mirror repository and so that merges via the primary lead to PRs on the seconday being detected as "manually merged".

If it is dangerous to do this by default, this could be a configurable option, e.g. in the Settings --> Repository --> Pull Requests section.

Screenshots

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions