##// END OF EJS Templates
repos: cleannup and fix landing-ref code....
super-admin -
r4852:07a18b11 default
parent child Browse files
Show More
@@ -22,6 +22,7 b' import mock'
22 import pytest
22 import pytest
23
23
24 from rhodecode.model.repo import RepoModel
24 from rhodecode.model.repo import RepoModel
25 from rhodecode.model.scm import ScmModel
25 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
26 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
26 from rhodecode.api.tests.utils import (
27 from rhodecode.api.tests.utils import (
27 build_data, api_call, assert_error, assert_ok, crash, jsonify)
28 build_data, api_call, assert_error, assert_ok, crash, jsonify)
@@ -65,8 +66,8 b' class TestApiUpdateRepo(object):'
65 ({'push_uri': 'http://example.com/repo_push'},
66 ({'push_uri': 'http://example.com/repo_push'},
66 {'push_uri': 'http://example.com/repo_push'}),
67 {'push_uri': 'http://example.com/repo_push'}),
67
68
68 ({'landing_rev': 'rev:tip'},
69 ({'landing_rev': None}, # auto-updated based on type of repo
69 {'landing_rev': ['rev', 'tip']}),
70 {'landing_rev': [None, None]}),
70
71
71 ({'enable_statistics': True},
72 ({'enable_statistics': True},
72 SAME_AS_UPDATES),
73 SAME_AS_UPDATES),
@@ -97,6 +98,12 b' class TestApiUpdateRepo(object):'
97 if updates.get('_group'):
98 if updates.get('_group'):
98 fixture.create_repo_group(updates['_group'])
99 fixture.create_repo_group(updates['_group'])
99
100
101 if 'landing_rev' in updates:
102 default_landing_ref, _lbl = ScmModel.backend_landing_ref(backend.alias)
103 _type, _name = default_landing_ref.split(':')
104 updates['landing_rev'] = default_landing_ref
105 expected['landing_rev'] = [_type, _name]
106
100 expected_api_data = repo.get_api_data(include_secrets=True)
107 expected_api_data = repo.get_api_data(include_secrets=True)
101 if expected is SAME_AS_UPDATES:
108 if expected is SAME_AS_UPDATES:
102 expected_api_data.update(updates)
109 expected_api_data.update(updates)
@@ -55,6 +55,7 b' class GitRepository(BaseRepository):'
55 Git repository backend.
55 Git repository backend.
56 """
56 """
57 DEFAULT_BRANCH_NAME = os.environ.get('GIT_DEFAULT_BRANCH_NAME') or 'master'
57 DEFAULT_BRANCH_NAME = os.environ.get('GIT_DEFAULT_BRANCH_NAME') or 'master'
58 DEFAULT_REF = 'branch:{}'.format(DEFAULT_BRANCH_NAME)
58
59
59 contact = BaseRepository.DEFAULT_CONTACT
60 contact = BaseRepository.DEFAULT_CONTACT
60
61
@@ -497,7 +497,7 b' class RepoModel(BaseModel):'
497
497
498 def _create_repo(self, repo_name, repo_type, description, owner,
498 def _create_repo(self, repo_name, repo_type, description, owner,
499 private=False, clone_uri=None, repo_group=None,
499 private=False, clone_uri=None, repo_group=None,
500 landing_rev='rev:tip', fork_of=None,
500 landing_rev=None, fork_of=None,
501 copy_fork_permissions=False, enable_statistics=False,
501 copy_fork_permissions=False, enable_statistics=False,
502 enable_locking=False, enable_downloads=False,
502 enable_locking=False, enable_downloads=False,
503 copy_group_permissions=False,
503 copy_group_permissions=False,
@@ -512,6 +512,8 b' class RepoModel(BaseModel):'
512 owner = self._get_user(owner)
512 owner = self._get_user(owner)
513 fork_of = self._get_repo(fork_of)
513 fork_of = self._get_repo(fork_of)
514 repo_group = self._get_repo_group(safe_int(repo_group))
514 repo_group = self._get_repo_group(safe_int(repo_group))
515 default_landing_ref, _lbl = ScmModel.backend_landing_ref(repo_type)
516 landing_rev = landing_rev or default_landing_ref
515
517
516 try:
518 try:
517 repo_name = safe_unicode(repo_name)
519 repo_name = safe_unicode(repo_name)
@@ -966,6 +966,8 b' class ScmModel(BaseModel):'
966
966
967 :param repo:
967 :param repo:
968 """
968 """
969 from rhodecode.lib.vcs.backends.git import GitRepository
970
969 _ = translator
971 _ = translator
970 repo = self._get_repo(repo)
972 repo = self._get_repo(repo)
971
973
@@ -984,12 +986,13 b' class ScmModel(BaseModel):'
984 ]
986 ]
985
987
986 if not repo:
988 if not repo:
989 # presented at NEW repo creation
987 return default_choices, default_ref_options
990 return default_choices, default_ref_options
988
991
989 repo = repo.scm_instance()
992 repo = repo.scm_instance()
990
993
991 ref_options = [('rev:tip', 'latest tip')]
994 ref_options = [(default_landing_ref, landing_ref_lbl)]
992 choices = ['rev:tip']
995 choices = [default_landing_ref]
993
996
994 # branches
997 # branches
995 branch_group = [(u'branch:%s' % safe_unicode(b), safe_unicode(b)) for b in repo.branches]
998 branch_group = [(u'branch:%s' % safe_unicode(b), safe_unicode(b)) for b in repo.branches]
@@ -26,11 +26,6 b' from rhodecode.model.validation_schema.u'
26 from rhodecode.model.validation_schema import validators, preparers, types
26 from rhodecode.model.validation_schema import validators, preparers, types
27
27
28 DEFAULT_LANDING_REF = 'rev:tip'
28 DEFAULT_LANDING_REF = 'rev:tip'
29 DEFAULT_BACKEND_LANDING_REF = {
30 'hg': 'branch:default',
31 'git': 'branch:master',
32 'svn': 'rev:tip',
33 }
34
29
35
30
36 def get_group_and_repo(repo_name):
31 def get_group_and_repo(repo_name):
@@ -80,12 +75,13 b' def deferred_sync_uri_validator(node, kw'
80
75
81 @colander.deferred
76 @colander.deferred
82 def deferred_landing_ref_widget(node, kw):
77 def deferred_landing_ref_widget(node, kw):
78 from rhodecode.model.scm import ScmModel
79
83 repo_type = kw.get('repo_type')
80 repo_type = kw.get('repo_type')
84 default_opts = []
81 default_opts = []
85 if repo_type:
82 if repo_type:
86 default_opts.append(
83 default_landing_ref, _lbl = ScmModel.backend_landing_ref(repo_type)
87 (DEFAULT_BACKEND_LANDING_REF[repo_type],
84 default_opts.append((default_landing_ref, default_landing_ref))
88 DEFAULT_BACKEND_LANDING_REF[repo_type]))
89
85
90 items = kw.get('repo_ref_items', default_opts)
86 items = kw.get('repo_ref_items', default_opts)
91 items = convert_to_optgroup(items)
87 items = convert_to_optgroup(items)
@@ -39,6 +39,7 b' from rhodecode.model.repo_group import R'
39 from rhodecode.model.user_group import UserGroupModel
39 from rhodecode.model.user_group import UserGroupModel
40 from rhodecode.model.gist import GistModel
40 from rhodecode.model.gist import GistModel
41 from rhodecode.model.auth_token import AuthTokenModel
41 from rhodecode.model.auth_token import AuthTokenModel
42 from rhodecode.model.scm import ScmModel
42 from rhodecode.authentication.plugins.auth_rhodecode import \
43 from rhodecode.authentication.plugins.auth_rhodecode import \
43 RhodeCodeAuthPlugin
44 RhodeCodeAuthPlugin
44
45
@@ -190,15 +191,19 b' class Fixture(object):'
190 return context()
191 return context()
191
192
192 def _get_repo_create_params(self, **custom):
193 def _get_repo_create_params(self, **custom):
194 repo_type = custom.get('repo_type') or 'hg'
195
196 default_landing_ref, landing_ref_lbl = ScmModel.backend_landing_ref(repo_type)
197
193 defs = {
198 defs = {
194 'repo_name': None,
199 'repo_name': None,
195 'repo_type': 'hg',
200 'repo_type': repo_type,
196 'clone_uri': '',
201 'clone_uri': '',
197 'push_uri': '',
202 'push_uri': '',
198 'repo_group': '-1',
203 'repo_group': '-1',
199 'repo_description': 'DESC',
204 'repo_description': 'DESC',
200 'repo_private': False,
205 'repo_private': False,
201 'repo_landing_rev': 'rev:tip',
206 'repo_landing_commit_ref': default_landing_ref,
202 'repo_copy_permissions': False,
207 'repo_copy_permissions': False,
203 'repo_state': Repository.STATE_CREATED,
208 'repo_state': Repository.STATE_CREATED,
204 }
209 }
@@ -279,14 +284,16 b' class Fixture(object):'
279 def create_fork(self, repo_to_fork, fork_name, **kwargs):
284 def create_fork(self, repo_to_fork, fork_name, **kwargs):
280 repo_to_fork = Repository.get_by_repo_name(repo_to_fork)
285 repo_to_fork = Repository.get_by_repo_name(repo_to_fork)
281
286
282 form_data = self._get_repo_create_params(repo_name=fork_name,
287 form_data = self._get_repo_create_params(
288 repo_name=fork_name,
283 fork_parent_id=repo_to_fork.repo_id,
289 fork_parent_id=repo_to_fork.repo_id,
284 repo_type=repo_to_fork.repo_type,
290 repo_type=repo_to_fork.repo_type,
285 **kwargs)
291 **kwargs)
292
286 #TODO: fix it !!
293 #TODO: fix it !!
287 form_data['description'] = form_data['repo_description']
294 form_data['description'] = form_data['repo_description']
288 form_data['private'] = form_data['repo_private']
295 form_data['private'] = form_data['repo_private']
289 form_data['landing_rev'] = form_data['repo_landing_rev']
296 form_data['landing_rev'] = form_data['repo_landing_commit_ref']
290
297
291 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN)
298 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN)
292 RepoModel().create_fork(form_data, cur_user=owner)
299 RepoModel().create_fork(form_data, cur_user=owner)
General Comments 0
You need to be logged in to leave comments. Login now