##// END OF EJS Templates
extended repo creation by repo type. fixed fork creation to maintain repo type.
marcink -
r659:758f64f3 beta
parent child Browse files
Show More
@@ -151,7 +151,7 b' class SettingsController(BaseController)'
151 151 def fork_create(self, repo_name):
152 152 repo_model = RepoModel()
153 153 c.repo_info = repo_model.get(repo_name)
154 _form = RepoForkForm()()
154 _form = RepoForkForm(old_data={'repo_type':c.repo_info.repo_type})()
155 155 form_result = {}
156 156 try:
157 157 form_result = _form.to_python(dict(request.POST))
@@ -11,7 +11,7 b' from rhodecode.lib.utils import get_repo'
11 11 from rhodecode.model import meta
12 12 from rhodecode.model.hg import _get_repos_cached, \
13 13 _get_repos_switcher_cached
14
14 from vcs import BACKENDS
15 15 class BaseController(WSGIController):
16 16
17 17 def __before__(self):
@@ -20,7 +20,7 b' class BaseController(WSGIController):'
20 20 c.repo_name = get_repo_slug(request)
21 21 c.cached_repo_list = _get_repos_cached()
22 22 c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list)
23
23 c.backends = BACKENDS.keys()
24 24 if c.repo_name:
25 25 cached_repo = c.cached_repo_list.get(c.repo_name)
26 26
@@ -289,18 +289,20 b' def send_email(recipients, subject, body'
289 289
290 290 @task
291 291 def create_repo_fork(form_data, cur_user):
292 import os
293 292 from rhodecode.model.repo import RepoModel
294
293 from vcs import get_backend
294 log = create_repo_fork.get_logger()
295 295 repo_model = RepoModel(get_session())
296 296 repo_model.create(form_data, cur_user, just_db=True, fork=True)
297
298 repos_path = get_hg_ui_settings()['paths_root_path'].replace('*', '')
299 repo_path = os.path.join(repos_path, form_data['repo_name'])
297 repo_name = form_data['repo_name']
298 repos_path = get_hg_ui_settings()['paths_root_path']
299 repo_path = os.path.join(repos_path, repo_name)
300 300 repo_fork_path = os.path.join(repos_path, form_data['fork_name'])
301 alias = form_data['repo_type']
301 302
302 MercurialRepository(str(repo_fork_path), True, clone_url=str(repo_path))
303
303 log.info('creating repo fork %s as %s', repo_name, repo_path)
304 backend = get_backend(alias)
305 backend(str(repo_fork_path), create=True, src_url=str(repo_path))
304 306
305 307 def __get_codes_stats(repo_name):
306 308 LANGUAGES_EXTENSIONS = ['action', 'adp', 'ashx', 'asmx',
@@ -345,8 +345,9 b' def repo2db_mapper(initial_repo_list, re'
345 345 form_data = {
346 346 'repo_name':name,
347 347 'repo_type':repo.alias,
348 'description':repo.description if repo.description != 'unknown' else \
349 'auto description for %s' % name,
348 'description':repo.description \
349 if repo.description != 'unknown' else \
350 '%s repository' % name,
350 351 'private':False
351 352 }
352 353 rm.create(form_data, user, just_db=True)
@@ -30,6 +30,7 b' from rhodecode.model.user import UserMod'
30 30 from rhodecode.model.repo import RepoModel
31 31 from rhodecode.model.db import User
32 32 from webhelpers.pylonslib.secure_form import authentication_token
33 from vcs import BACKENDS
33 34 import formencode
34 35 import logging
35 36 import os
@@ -147,6 +148,15 b' def ValidRepoName(edit, old_data):'
147 148
148 149 return _ValidRepoName
149 150
151 def ValidForkType(old_data):
152 class _ValidForkType(formencode.validators.FancyValidator):
153
154 def to_python(self, value, state):
155 if old_data['repo_type'] != value:
156 raise formencode.Invalid(_('Fork have to be the same type as original'), value, state)
157 return value
158 return _ValidForkType
159
150 160 class ValidPerms(formencode.validators.FancyValidator):
151 161 messages = {'perm_new_user_name':_('This username is not valid')}
152 162
@@ -292,7 +302,7 b' def RepoForm(edit=False, old_data={}):'
292 302 repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
293 303 description = UnicodeString(strip=True, min=1, not_empty=True)
294 304 private = StringBoolean(if_missing=False)
295
305 repo_type = OneOf(BACKENDS.keys())
296 306 if edit:
297 307 user = All(Int(not_empty=True), ValidRepoUser)
298 308
@@ -306,7 +316,7 b' def RepoForkForm(edit=False, old_data={}'
306 316 fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
307 317 description = UnicodeString(strip=True, min=1, not_empty=True)
308 318 private = StringBoolean(if_missing=False)
309
319 repo_type = All(ValidForkType(old_data), OneOf(BACKENDS.keys()))
310 320 return _RepoForkForm
311 321
312 322 def RepoSettingsForm(edit=False, old_data={}):
@@ -21,7 +21,7 b' Created on Jun 5, 2010'
21 21 model for handling repositories actions
22 22 :author: marcink
23 23 """
24
24 from vcs.backends import get_repo, get_backend
25 25 from datetime import datetime
26 26 from pylons import app_globals as g
27 27 from rhodecode.model.db import Repository, RepoToPerm, User, Permission
@@ -151,7 +151,7 b' class RepoModel(object):'
151 151 self.sa.add(repo_to_perm)
152 152 self.sa.commit()
153 153 if not just_db:
154 self.__create_repo(repo_name)
154 self.__create_repo(repo_name, form_data['repo_type'])
155 155 except:
156 156 log.error(traceback.format_exc())
157 157 self.sa.rollback()
@@ -182,13 +182,13 b' class RepoModel(object):'
182 182 self.sa.rollback()
183 183 raise
184 184
185 def __create_repo(self, repo_name):
185 def __create_repo(self, repo_name, alias):
186 186 from rhodecode.lib.utils import check_repo
187 187 repo_path = os.path.join(g.base_path, repo_name)
188 188 if check_repo(repo_name, g.base_path):
189 189 log.info('creating repo %s in %s', repo_name, repo_path)
190 from vcs.backends.hg import MercurialRepository
191 MercurialRepository(repo_path, create=True)
190 backend = get_backend(alias)
191 backend(repo_path, create=True)
192 192
193 193 def __rename_repo(self, old, new):
194 194 log.info('renaming repo from %s to %s', old, new)
@@ -35,6 +35,14 b''
35 35 </div>
36 36 </div>
37 37 <div class="field">
38 <div class="label">
39 <label for="repo_type">${_('Type')}:</label>
40 </div>
41 <div class="input">
42 ${h.select('repo_type','hg',c.backends,class_="small")}
43 </div>
44 </div>
45 <div class="field">
38 46 <div class="label label-textarea">
39 47 <label for="description">${_('Description')}:</label>
40 48 </div>
@@ -32,6 +32,14 b''
32 32 </div>
33 33 </div>
34 34 <div class="field">
35 <div class="label">
36 <label for="repo_type">${_('Type')}:</label>
37 </div>
38 <div class="input">
39 ${h.select('repo_type','hg',c.backends,class_="small")}
40 </div>
41 </div>
42 <div class="field">
35 43 <div class="label label-textarea">
36 44 <label for="description">${_('Description')}:</label>
37 45 </div>
@@ -35,7 +35,14 b''
35 35 ${h.text('repo_name',class_="small")}
36 36 </div>
37 37 </div>
38
38 <div class="field">
39 <div class="label">
40 <label for="repo_type">${_('Type')}:</label>
41 </div>
42 <div class="input">
43 ${h.select('repo_type','hg',c.backends,class_="small")}
44 </div>
45 </div>
39 46 <div class="field">
40 47 <div class="label label-textarea">
41 48 <label for="description">${_('Description')}:</label>
@@ -30,6 +30,7 b''
30 30 </div>
31 31 <div class="input">
32 32 ${h.text('fork_name',class_="small")}
33 ${h.hidden('repo_type',c.repo_info.repo_type)}
33 34 </div>
34 35 </div>
35 36 <div class="field">
@@ -17,7 +17,7 b' class TestLoginController(TestController'
17 17 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
18 18 assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user'
19 19 response = response.follow()
20 assert 'auto description for vcs_test' in response.body
20 assert 'vcs_test repository' in response.body
21 21
22 22 def test_login_regular_ok(self):
23 23 response = self.app.post(url(controller='login', action='index'),
@@ -27,7 +27,7 b' class TestLoginController(TestController'
27 27 assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
28 28 assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user'
29 29 response = response.follow()
30 assert 'auto description for vcs_test' in response.body
30 assert 'vcs_test repository' in response.body
31 31 assert '<a title="Admin" href="/_admin">' not in response.body
32 32
33 33 def test_login_ok_came_from(self):
General Comments 0
You need to be logged in to leave comments. Login now