diff --git a/rhodecode/controllers/settings.py b/rhodecode/controllers/settings.py
--- a/rhodecode/controllers/settings.py
+++ b/rhodecode/controllers/settings.py
@@ -151,7 +151,7 @@ class SettingsController(BaseController)
def fork_create(self, repo_name):
repo_model = RepoModel()
c.repo_info = repo_model.get(repo_name)
- _form = RepoForkForm()()
+ _form = RepoForkForm(old_data={'repo_type':c.repo_info.repo_type})()
form_result = {}
try:
form_result = _form.to_python(dict(request.POST))
diff --git a/rhodecode/lib/base.py b/rhodecode/lib/base.py
--- a/rhodecode/lib/base.py
+++ b/rhodecode/lib/base.py
@@ -11,28 +11,28 @@ from rhodecode.lib.utils import get_repo
from rhodecode.model import meta
from rhodecode.model.hg import _get_repos_cached, \
_get_repos_switcher_cached
-
+from vcs import BACKENDS
class BaseController(WSGIController):
-
+
def __before__(self):
c.rhodecode_version = __version__
c.rhodecode_name = config['rhodecode_title']
c.repo_name = get_repo_slug(request)
c.cached_repo_list = _get_repos_cached()
c.repo_switcher_list = _get_repos_switcher_cached(c.cached_repo_list)
-
+ c.backends = BACKENDS.keys()
if c.repo_name:
cached_repo = c.cached_repo_list.get(c.repo_name)
-
+
if cached_repo:
c.repository_tags = cached_repo.tags
c.repository_branches = cached_repo.branches
else:
c.repository_tags = {}
c.repository_branches = {}
-
+
self.sa = meta.Session()
-
+
def __call__(self, environ, start_response):
"""Invoke the Controller"""
# WSGIController.__call__ dispatches to the Controller method
diff --git a/rhodecode/lib/celerylib/tasks.py b/rhodecode/lib/celerylib/tasks.py
--- a/rhodecode/lib/celerylib/tasks.py
+++ b/rhodecode/lib/celerylib/tasks.py
@@ -289,18 +289,20 @@ def send_email(recipients, subject, body
@task
def create_repo_fork(form_data, cur_user):
- import os
from rhodecode.model.repo import RepoModel
-
+ from vcs import get_backend
+ log = create_repo_fork.get_logger()
repo_model = RepoModel(get_session())
repo_model.create(form_data, cur_user, just_db=True, fork=True)
-
- repos_path = get_hg_ui_settings()['paths_root_path'].replace('*', '')
- repo_path = os.path.join(repos_path, form_data['repo_name'])
+ repo_name = form_data['repo_name']
+ repos_path = get_hg_ui_settings()['paths_root_path']
+ repo_path = os.path.join(repos_path, repo_name)
repo_fork_path = os.path.join(repos_path, form_data['fork_name'])
+ alias = form_data['repo_type']
- MercurialRepository(str(repo_fork_path), True, clone_url=str(repo_path))
-
+ log.info('creating repo fork %s as %s', repo_name, repo_path)
+ backend = get_backend(alias)
+ backend(str(repo_fork_path), create=True, src_url=str(repo_path))
def __get_codes_stats(repo_name):
LANGUAGES_EXTENSIONS = ['action', 'adp', 'ashx', 'asmx',
diff --git a/rhodecode/lib/utils.py b/rhodecode/lib/utils.py
--- a/rhodecode/lib/utils.py
+++ b/rhodecode/lib/utils.py
@@ -345,8 +345,9 @@ def repo2db_mapper(initial_repo_list, re
form_data = {
'repo_name':name,
'repo_type':repo.alias,
- 'description':repo.description if repo.description != 'unknown' else \
- 'auto description for %s' % name,
+ 'description':repo.description \
+ if repo.description != 'unknown' else \
+ '%s repository' % name,
'private':False
}
rm.create(form_data, user, just_db=True)
diff --git a/rhodecode/model/forms.py b/rhodecode/model/forms.py
--- a/rhodecode/model/forms.py
+++ b/rhodecode/model/forms.py
@@ -30,6 +30,7 @@ from rhodecode.model.user import UserMod
from rhodecode.model.repo import RepoModel
from rhodecode.model.db import User
from webhelpers.pylonslib.secure_form import authentication_token
+from vcs import BACKENDS
import formencode
import logging
import os
@@ -147,6 +148,15 @@ def ValidRepoName(edit, old_data):
return _ValidRepoName
+def ValidForkType(old_data):
+ class _ValidForkType(formencode.validators.FancyValidator):
+
+ def to_python(self, value, state):
+ if old_data['repo_type'] != value:
+ raise formencode.Invalid(_('Fork have to be the same type as original'), value, state)
+ return value
+ return _ValidForkType
+
class ValidPerms(formencode.validators.FancyValidator):
messages = {'perm_new_user_name':_('This username is not valid')}
@@ -292,7 +302,7 @@ def RepoForm(edit=False, old_data={}):
repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
description = UnicodeString(strip=True, min=1, not_empty=True)
private = StringBoolean(if_missing=False)
-
+ repo_type = OneOf(BACKENDS.keys())
if edit:
user = All(Int(not_empty=True), ValidRepoUser)
@@ -306,7 +316,7 @@ def RepoForkForm(edit=False, old_data={}
fork_name = All(UnicodeString(strip=True, min=1, not_empty=True), ValidRepoName(edit, old_data))
description = UnicodeString(strip=True, min=1, not_empty=True)
private = StringBoolean(if_missing=False)
-
+ repo_type = All(ValidForkType(old_data), OneOf(BACKENDS.keys()))
return _RepoForkForm
def RepoSettingsForm(edit=False, old_data={}):
diff --git a/rhodecode/model/repo.py b/rhodecode/model/repo.py
--- a/rhodecode/model/repo.py
+++ b/rhodecode/model/repo.py
@@ -21,7 +21,7 @@ Created on Jun 5, 2010
model for handling repositories actions
:author: marcink
"""
-
+from vcs.backends import get_repo, get_backend
from datetime import datetime
from pylons import app_globals as g
from rhodecode.model.db import Repository, RepoToPerm, User, Permission
@@ -151,7 +151,7 @@ class RepoModel(object):
self.sa.add(repo_to_perm)
self.sa.commit()
if not just_db:
- self.__create_repo(repo_name)
+ self.__create_repo(repo_name, form_data['repo_type'])
except:
log.error(traceback.format_exc())
self.sa.rollback()
@@ -182,13 +182,13 @@ class RepoModel(object):
self.sa.rollback()
raise
- def __create_repo(self, repo_name):
+ def __create_repo(self, repo_name, alias):
from rhodecode.lib.utils import check_repo
repo_path = os.path.join(g.base_path, repo_name)
if check_repo(repo_name, g.base_path):
log.info('creating repo %s in %s', repo_name, repo_path)
- from vcs.backends.hg import MercurialRepository
- MercurialRepository(repo_path, create=True)
+ backend = get_backend(alias)
+ backend(repo_path, create=True)
def __rename_repo(self, old, new):
log.info('renaming repo from %s to %s', old, new)
diff --git a/rhodecode/templates/admin/repos/repo_add.html b/rhodecode/templates/admin/repos/repo_add.html
--- a/rhodecode/templates/admin/repos/repo_add.html
+++ b/rhodecode/templates/admin/repos/repo_add.html
@@ -35,6 +35,14 @@
+
+
+
+
+ ${h.select('repo_type','hg',c.backends,class_="small")}
+
+
+
diff --git a/rhodecode/templates/admin/repos/repo_add_create_repository.html b/rhodecode/templates/admin/repos/repo_add_create_repository.html
--- a/rhodecode/templates/admin/repos/repo_add_create_repository.html
+++ b/rhodecode/templates/admin/repos/repo_add_create_repository.html
@@ -32,6 +32,14 @@
+
+
+
+
+ ${h.select('repo_type','hg',c.backends,class_="small")}
+
+
+
diff --git a/rhodecode/templates/admin/repos/repo_edit.html b/rhodecode/templates/admin/repos/repo_edit.html
--- a/rhodecode/templates/admin/repos/repo_edit.html
+++ b/rhodecode/templates/admin/repos/repo_edit.html
@@ -35,7 +35,14 @@
${h.text('repo_name',class_="small")}
-
+
+
+
+
+
+ ${h.select('repo_type','hg',c.backends,class_="small")}
+
+
diff --git a/rhodecode/templates/settings/repo_fork.html b/rhodecode/templates/settings/repo_fork.html
--- a/rhodecode/templates/settings/repo_fork.html
+++ b/rhodecode/templates/settings/repo_fork.html
@@ -30,6 +30,7 @@
${h.text('fork_name',class_="small")}
+ ${h.hidden('repo_type',c.repo_info.repo_type)}
diff --git a/rhodecode/tests/functional/test_login.py b/rhodecode/tests/functional/test_login.py
--- a/rhodecode/tests/functional/test_login.py
+++ b/rhodecode/tests/functional/test_login.py
@@ -17,8 +17,8 @@ class TestLoginController(TestController
assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
assert response.session['rhodecode_user'].username == 'test_admin', 'wrong logged in user'
response = response.follow()
- assert 'auto description for vcs_test' in response.body
-
+ assert 'vcs_test repository' in response.body
+
def test_login_regular_ok(self):
response = self.app.post(url(controller='login', action='index'),
{'username':'test_regular',
@@ -27,9 +27,9 @@ class TestLoginController(TestController
assert response.status == '302 Found', 'Wrong response code from login got %s' % response.status
assert response.session['rhodecode_user'].username == 'test_regular', 'wrong logged in user'
response = response.follow()
- assert 'auto description for vcs_test' in response.body
+ assert 'vcs_test repository' in response.body
assert '
' not in response.body
-
+
def test_login_ok_came_from(self):
test_came_from = '/_admin/users'
response = self.app.post(url(controller='login', action='index', came_from=test_came_from),
@@ -37,11 +37,11 @@ class TestLoginController(TestController
'password':'test12'})
assert response.status == '302 Found', 'Wrong response code from came from redirection'
response = response.follow()
-
+
assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
assert 'Users administration' in response.body, 'No proper title in response'
-
-
+
+
def test_login_short_password(self):
response = self.app.post(url(controller='login', action='index'),
{'username':'error',
@@ -55,15 +55,15 @@ class TestLoginController(TestController
{'username':'error',
'password':'test12'})
assert response.status == '200 OK', 'Wrong response from login page'
-
+
assert 'invalid user name' in response.body, 'No error username message in response'
assert 'invalid password' in response.body, 'No error password message in response'
-
-
+
+
def test_register(self):
response = self.app.get(url(controller='login', action='register'))
assert 'Sign Up to rhodecode' in response.body, 'wrong page for user registration'
-
+
def test_register_err_same_username(self):
response = self.app.post(url(controller='login', action='register'),
{'username':'test_admin',
@@ -71,10 +71,10 @@ class TestLoginController(TestController
'email':'goodmail@domain.com',
'name':'test',
'lastname':'test'})
-
+
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
- assert 'This username already exists' in response.body
-
+ assert 'This username already exists' in response.body
+
def test_register_err_wrong_data(self):
response = self.app.post(url(controller='login', action='register'),
{'username':'xs',
@@ -82,20 +82,20 @@ class TestLoginController(TestController
'email':'goodmailm',
'name':'test',
'lastname':'test'})
-
+
assert response.status == '200 OK', 'Wrong response from register page got %s' % response.status
assert 'An email address must contain a single @' in response.body
assert 'Please enter a value' in response.body
-
-
-
+
+
+
def test_register_ok(self):
username = 'test_regular4'
password = 'qweqwe'
email = 'marcin@test.com'
name = 'testname'
lastname = 'testlastname'
-
+
response = self.app.post(url(controller='login', action='register'),
{'username':username,
'password':password,
@@ -103,23 +103,23 @@ class TestLoginController(TestController
'name':name,
'lastname':lastname})
print response.body
- assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status
+ assert response.status == '302 Found', 'Wrong response from register page got %s' % response.status
assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
-
+
ret = self.sa.query(User).filter(User.username == 'test_regular4').one()
assert ret.username == username , 'field mismatch %s %s' % (ret.username, username)
assert check_password(password, ret.password) == True , 'password mismatch'
assert ret.email == email , 'field mismatch %s %s' % (ret.email, email)
assert ret.name == name , 'field mismatch %s %s' % (ret.name, name)
assert ret.lastname == lastname , 'field mismatch %s %s' % (ret.lastname, lastname)
-
-
- def test_forgot_password_wrong_mail(self):
+
+
+ def test_forgot_password_wrong_mail(self):
response = self.app.post(url(controller='login', action='password_reset'),
{'email':'marcin@wrongmail.org', })
-
+
assert "That e-mail address doesn't exist" in response.body, 'Missing error message about wrong email'
-
+
def test_forgot_password(self):
response = self.app.get(url(controller='login', action='password_reset'))
assert response.status == '200 OK', 'Wrong response from login page got %s' % response.status
@@ -129,19 +129,19 @@ class TestLoginController(TestController
email = 'marcin@python-works.com'
name = 'passwd'
lastname = 'reset'
-
+
response = self.app.post(url(controller='login', action='register'),
{'username':username,
'password':password,
'email':email,
'name':name,
- 'lastname':lastname})
+ 'lastname':lastname})
#register new user for email test
response = self.app.post(url(controller='login', action='password_reset'),
{'email':email, })
print response.session['flash']
assert 'You have successfully registered into rhodecode' in response.session['flash'][0], 'No flash message about user registration'
assert 'Your new password was sent' in response.session['flash'][1], 'No flash message about password reset'
-
-
-
+
+
+