Repository: WeblateOrg/weblate

Issue:
Hosted weblate tries to push to the wrong repository
### Describe the issue

Due to some refactoring, we have changed https://hosted.weblate.org/projects/calyxos/platform_packages_apps_Firewall/ push URL from `ssh://weblate@review.calyxos.org:29418/CalyxOS/platform_packages_apps_Firewall` to `ssh://weblate@review.calyxos.org:29418/CalyxOS/platform_external_calyx_datura`, however weblate still tries to push new commits to the old URL and fails, this can be seen at "Repository maintenance" page: `error: failed to push some refs to 'ssh://review.calyxos.org:29418/CalyxOS/platform_packages_apps_Firewall'`

I have tried to find similar issues here without luck, I have also tried swapping the URLs I could find in settings, but nothing was able to fix this. Is there a way to achieve this without deleting and recreating the component?

### I already tried

- [X] I've read and searched [the documentation](https://docs.weblate.org/).
- [X] I've searched for similar filed issues in this repository.

### Steps to reproduce the behavior

1. Go to https://hosted.weblate.org/projects/calyxos/platform_packages_apps_Firewall
2. Manage -> Settings -> Version control
3. Change "Repository push URL"
4. Translate some strings, commit the translations
5. Observe weblate tries to push the commits to the original push URL instead of the new one

### Expected behavior

Weblate pushes the new commits to the newly changed push URL

### Screenshots

_No response_

### Exception traceback

_No response_

### How do you run Weblate?

weblate.org service

### Weblate versions

_No response_

### Weblate deploy checks

_No response_

### Additional context

_No response_


Discussion:
This has something to do with Gerrit. Weblate correctly updated the push URL, but there is an additional `gerrit` remote which still has the old URL. I don't know gerrit at all, so any info why it configures another remote and how to keep it in sync would be useful.
`git-review` (which is what weblate uses to upload changes) creates a remote that is specified in the `.gitreview` file at the top level of each repository. In this case, the remote is `gerrit` which was specified in this file https://gitlab.com/CalyxOS/weblate/platform_packages_apps_Firewall/-/blob/android13/.gitreview and the new one is here https://gitlab.com/CalyxOS/weblate/platform_packages_apps_Firewall/-/blob/android14/.gitreview but it looks like the remote wasn't recreated after it was changed in `.gitreview`
This is documented behavior, it is only initialized based on `.gitreview`: https://docs.opendev.org/opendev/git-review/latest/installation.html#setup

Should Weblate update `gerrit` remote to match *Push URL* configured in Weblate? That would be the most straightforward fix here, but it would make it ignore the `.gitreview` file.

Weblate could either update `gerrit` remote based on _Push URL_ and ignore `.gitreview`, or remove `gerrit` remote before running `git review` and ignore _Push URL_.

Both have a disadvantage, but I'm leaning towards the first option since everything will be configurable through the web UI.

Resolving patch:
diff --git a/weblate/vcs/git.py b/weblate/vcs/git.py
--- a/weblate/vcs/git.py
+++ b/weblate/vcs/git.py
@@ -358,6 +358,11 @@ def remove(self, files: list[str], message: str, author: str | None = None) -> N
         self.execute(["rm", "--force", "--", *files])
         self.commit(message, author)
 
+    def get_remote_configure(
+        self, pull_url: str, push_url: str, branch: str, fast: bool = True
+    ) -> tuple[tuple[str, str, str | None], ...]:
+        return ()
+
     def configure_remote(
         self, pull_url: str, push_url: str, branch: str, fast: bool = True
     ) -> None:
@@ -388,6 +393,7 @@ def configure_remote(
                 "merge",
                 dumps(f"refs/heads/{branch}", ensure_ascii=False),
             ),
+            *self.get_remote_configure(pull_url, push_url, branch, fast),
         )
         self.branch = branch
 
@@ -551,6 +557,13 @@ def push(self, branch) -> None:
                     return
                 raise
 
+    def get_remote_configure(
+        self, pull_url: str, push_url: str, branch: str, fast: bool = True
+    ) -> tuple[tuple[str, str, str | None], ...]:
+        if push_url:
+            return (('remote "gerrit"', "url", push_url),)
+        return (('remote "gerrit"', "url", None),)
+
 
 class SubversionRepository(GitRepository):
     name = "Subversion"


Test patch: