Repository: WeblateOrg/weblate

Issue:
Gerrit tests are failing on openSUSE
Gerrit tests are failing in openSUSE build, regardless of version since 3.1 release:
```
[  927s] ERROR: test_merge_both (weblate.vcs.tests.test_vcs.VCSGerritTest)
[  927s] ----------------------------------------------------------------------
[  927s] Traceback (most recent call last):
[  927s]   File "/home/abuild/rpmbuild/BUILD/Weblate-3.5.1/weblate/vcs/tests/test_vcs.py", line 201, in test_merge_both
[  927s]     self.add_remote_commit()
[  927s]   File "/home/abuild/rpmbuild/BUILD/Weblate-3.5.1/weblate/vcs/tests/test_vcs.py", line 139, in add_remote_commit
[  927s]     repo.push()
[  927s]   File "/home/abuild/rpmbuild/BUILD/Weblate-3.5.1/weblate/vcs/git.py", line 378, in push
[  927s]     self.execute(['review', '--yes', self.branch])
[  927s]   File "/home/abuild/rpmbuild/BUILD/Weblate-3.5.1/weblate/vcs/base.py", line 194, in execute
[  927s]     args, self.path, fullcmd=fullcmd, local=self.local
[  927s]   File "/home/abuild/rpmbuild/BUILD/Weblate-3.5.1/weblate/vcs/base.py", line 178, in _popen
[  927s]     output.decode('utf-8')
[  927s] weblate.vcs.base.RepositoryException: No '.gitreview' file found in this repository. We don't know where
[  927s] your gerrit is.
[  927s] Please manually create a remote named "gerrit" and try again. (1)
```

We have git and git-review pulled in the system. Full log:
[weblate.txt](https://github.com/WeblateOrg/weblate/files/3034061/weblate.txt)



Discussion:
Newer gerrit versions need configuration in the repo and the test one lacks this. Thanks for reporting.

Resolving patch:
diff --git a/weblate/vcs/git.py b/weblate/vcs/git.py
--- a/weblate/vcs/git.py
+++ b/weblate/vcs/git.py
@@ -378,7 +378,8 @@ def _get_version(cls):
         return cls._popen(['review', '--version'], err=True).split()[-1]
 
     def push(self):
-        self.execute(['review', '--yes', self.branch])
+        if self.needs_push():
+            self.execute(['review', '--yes', self.branch])
 
 
 class SubversionRepository(GitRepository):


Test patch:
diff --git a/weblate/trans/tests/data/test-base-repo.git.tar b/weblate/trans/tests/data/test-base-repo.git.tar
Binary files a/weblate/trans/tests/data/test-base-repo.git.tar and b/weblate/trans/tests/data/test-base-repo.git.tar differ
diff --git a/weblate/trans/tests/data/test-base-repo.hg.tar b/weblate/trans/tests/data/test-base-repo.hg.tar
Binary files a/weblate/trans/tests/data/test-base-repo.hg.tar and b/weblate/trans/tests/data/test-base-repo.hg.tar differ
diff --git a/weblate/trans/tests/data/test-base-repo.svn.tar b/weblate/trans/tests/data/test-base-repo.svn.tar
Binary files a/weblate/trans/tests/data/test-base-repo.svn.tar and b/weblate/trans/tests/data/test-base-repo.svn.tar differ
diff --git a/weblate/vcs/tests/test_vcs.py b/weblate/vcs/tests/test_vcs.py
--- a/weblate/vcs/tests/test_vcs.py
+++ b/weblate/vcs/tests/test_vcs.py
@@ -88,7 +88,6 @@ def test_is_supported_cache(self):
 class VCSGitTest(TestCase, RepoTestMixin, TempDirMixin):
     _class = GitRepository
     _vcs = 'git'
-    _can_push = True
     _sets_push = True
 
     def setUp(self):
@@ -100,6 +99,10 @@ def setUp(self):
 
         self.create_temp()
         self.repo = self.clone_repo(self.tempdir)
+        self.fixup_repo(self.repo)
+
+    def fixup_repo(self, repo):
+        return
 
     def clone_repo(self, path):
         return self._class.clone(
@@ -116,6 +119,8 @@ def add_remote_commit(self, conflict=False):
         tempdir = tempfile.mkdtemp()
         try:
             repo = self.clone_repo(tempdir)
+            self.fixup_repo(repo)
+
             with repo.lock:
                 repo.set_committer('Second Bar', 'second@example.net')
             if conflict:
@@ -210,19 +215,13 @@ def test_rebase_both(self):
     def test_merge_conflict(self):
         self.add_remote_commit(conflict=True)
         self.test_commit()
-        if self._can_push:
-            with self.assertRaises(RepositoryException):
-                self.test_merge()
-        else:
+        with self.assertRaises(RepositoryException):
             self.test_merge()
 
     def test_rebase_conflict(self):
         self.add_remote_commit(conflict=True)
         self.test_commit()
-        if self._can_push:
-            with self.assertRaises(RepositoryException):
-                self.test_rebase()
-        else:
+        with self.assertRaises(RepositoryException):
             self.test_rebase()
 
     def test_upstream_changes(self):
@@ -412,7 +411,22 @@ def test_get_file(self):
 class VCSGerritTest(VCSGitTest):
     _class = GitWithGerritRepository
     _vcs = 'git'
-    _can_push = False
+
+    def fixup_repo(self, repo):
+        # Create commit-msg hook, so that git-review doesn't try
+        # to create one
+        hook = os.path.join(repo.path, '.git', 'hooks', 'commit-msg')
+        with open(hook, 'w') as handle:
+            handle.write('#!/bin/sh\nexit 0\n')
+        os.chmod(hook, 0o755)
+
+    def add_remote_commit(self, conflict=False):
+        # Use Git to create changed upstream repo
+        self._class = GitRepository
+        try:
+            super(VCSGerritTest, self).add_remote_commit(conflict)
+        finally:
+            self._class = GitWithGerritRepository
 
 
 class VCSGithubTest(VCSGitTest):