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