Commit 06df9177 authored by Michal Čihař's avatar Michal Čihař

Implement repository configuration

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 075910b4
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
# #
from weblate.trans.tests.test_models import RepoTestCase from weblate.trans.tests.test_models import RepoTestCase
from weblate.trans.vcs import GitRepository from weblate.trans.vcs import GitRepository, RepositoryException
import tempfile import tempfile
import shutil import shutil
...@@ -170,3 +170,13 @@ class VCSGitTest(RepoTestCase): ...@@ -170,3 +170,13 @@ class VCSGitTest(RepoTestCase):
self.repo.get_config('remote.origin.fetch'), self.repo.get_config('remote.origin.fetch'),
'+refs/heads/branch:refs/remotes/origin/branch', '+refs/heads/branch:refs/remotes/origin/branch',
) )
def test_configure_branch(self):
# Existing branch
self.repo.configure_branch('master')
self.assertRaises(
RepositoryException,
self.repo.configure_branch,
('branch')
)
...@@ -34,10 +34,6 @@ class RepositoryException(Exception): ...@@ -34,10 +34,6 @@ class RepositoryException(Exception):
class Repository(object): class Repository(object):
""" """
Basic repository object. Basic repository object.
Currently missing methods:
- branch configuration (SubProject.configure_branch)
""" """
_last_revision = None _last_revision = None
_last_remote_revision = None _last_remote_revision = None
...@@ -192,6 +188,12 @@ class Repository(object): ...@@ -192,6 +188,12 @@ class Repository(object):
""" """
raise NotImplementedError() raise NotImplementedError()
def configure_branch(self, branch):
"""
Configure repository branch.
"""
raise NotImplementedError()
class GitRepository(Repository): class GitRepository(Repository):
""" """
...@@ -376,3 +378,20 @@ class GitRepository(Repository): ...@@ -376,3 +378,20 @@ class GitRepository(Repository):
self._execute( self._execute(
['remote', 'set-branches', '--add', 'origin', branch] ['remote', 'set-branches', '--add', 'origin', branch]
) )
def configure_branch(self, branch):
"""
Configure repository branch.
"""
# List of branches (we get additional * there, but we don't care)
branches = self._execute(['branch']).split()
if branch in branches:
return
# Add branch
self._execute(
['branch', '--track', branch, 'origin/{0}'.format(branch)]
)
# Checkout
self._execute(['checkout', branch])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment