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

Closed
opened 2025-11-02 08:02:00 -06:00 by GiteaMirror · 2 comments
Owner

Originally created by @xyzroller on GitHub (Jan 4, 2022).

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

Originally created by @xyzroller on GitHub (Jan 4, 2022). ### 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](https://codeberg.org). 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](https://git-scm.com/docs/git-push#Documentation/git-push.txt---mirror) ## 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](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally#error-failed-to-push-some-refs) -- 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_
Author
Owner

@SPC-code commented on GitHub (Jan 5, 2024):

Is there a way to fix this behavior? We use gitea as a stand-alone repository and github as a push mirror. The problem is that all Merge requests on github are automatically closed.

@SPC-code commented on GitHub (Jan 5, 2024): Is there a way to fix this behavior? We use gitea as a stand-alone repository and github as a push mirror. The problem is that all Merge requests on github are automatically closed.
Author
Owner

@a1012112796 commented on GitHub (Sep 2, 2024):

fixd by https://github.com/go-gitea/gitea/pull/31931

@a1012112796 commented on GitHub (Sep 2, 2024): fixd by https://github.com/go-gitea/gitea/pull/31931
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8314