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