Show More
@@ -120,8 +120,10 b' class ReposController(BaseController):' | |||
|
120 | 120 | |
|
121 | 121 | c.repos_list = [('', _('--REMOVE FORK--'))] |
|
122 | 122 | c.repos_list += [(x.repo_id, x.repo_name) for x in |
|
123 |
Repository.query().order_by(Repository.repo_name).all() |
|
|
123 | Repository.query().order_by(Repository.repo_name).all() | |
|
124 | if x.repo_id != c.repo_info.repo_id] | |
|
124 | 125 | |
|
126 | defaults['id_fork_of'] = db_repo.fork.repo_id if db_repo.fork else '' | |
|
125 | 127 | return defaults |
|
126 | 128 | |
|
127 | 129 | @HasPermissionAllDecorator('hg.admin') |
@@ -417,11 +419,11 b' class ReposController(BaseController):' | |||
|
417 | 419 | repo = ScmModel().mark_as_fork(repo_name, fork_id, |
|
418 | 420 | self.rhodecode_user.username) |
|
419 | 421 | fork = repo.fork.repo_name if repo.fork else _('Nothing') |
|
420 | Session.commit() | |
|
421 | h.flash(_('Marked repo %s as fork of %s') % (repo_name,fork), | |
|
422 | Session().commit() | |
|
423 | h.flash(_('Marked repo %s as fork of %s') % (repo_name, fork), | |
|
422 | 424 | category='success') |
|
423 | 425 | except Exception, e: |
|
424 | raise | |
|
426 | log.error(traceback.format_exc()) | |
|
425 | 427 | h.flash(_('An error occurred during this operation'), |
|
426 | 428 | category='error') |
|
427 | 429 |
@@ -380,6 +380,8 b' class ScmModel(BaseModel):' | |||
|
380 | 380 | def mark_as_fork(self, repo, fork, user): |
|
381 | 381 | repo = self.__get_repo(repo) |
|
382 | 382 | fork = self.__get_repo(fork) |
|
383 | if fork and repo.repo_id == fork.repo_id: | |
|
384 | raise Exception("Cannot set repository as fork of itself") | |
|
383 | 385 | repo.fork = fork |
|
384 | 386 | self.sa.add(repo) |
|
385 | 387 | return repo |
@@ -160,5 +160,5 b' class TestController(TestCase):' | |||
|
160 | 160 | if not msg in response.session['flash'][0][1]: |
|
161 | 161 | self.fail( |
|
162 | 162 | 'msg `%s` not found in session flash: got `%s` instead' % ( |
|
163 |
msg, response.session['flash'] |
|
|
163 | msg, response.session['flash']) | |
|
164 | 164 | ) |
@@ -1,10 +1,11 b'' | |||
|
1 | 1 | # -*- coding: utf-8 -*- |
|
2 | 2 | |
|
3 | 3 | from rhodecode.lib.auth import get_crypt_password, check_password |
|
4 | from rhodecode.model.db import User, RhodeCodeSetting | |
|
4 | from rhodecode.model.db import User, RhodeCodeSetting, Repository | |
|
5 | 5 | from rhodecode.tests import * |
|
6 | 6 | from rhodecode.lib import helpers as h |
|
7 | 7 | from rhodecode.model.user import UserModel |
|
8 | from rhodecode.model.scm import ScmModel | |
|
8 | 9 | |
|
9 | 10 | |
|
10 | 11 | class TestAdminSettingsController(TestController): |
@@ -211,3 +212,55 b' class TestAdminSettingsController(TestCo' | |||
|
211 | 212 | old_data={})._messages['username_exists'] |
|
212 | 213 | msg = h.html_escape(msg % {'username': 'test_admin'}) |
|
213 | 214 | response.mustcontain(u"%s" % msg) |
|
215 | ||
|
216 | def test_set_repo_fork_has_no_self_id(self): | |
|
217 | self.log_user() | |
|
218 | repo = Repository.get_by_repo_name(HG_REPO) | |
|
219 | response = self.app.get(url('edit_repo', repo_name=HG_REPO)) | |
|
220 | opt = """<option value="%s">vcs_test_git</option>""" % repo.repo_id | |
|
221 | assert opt not in response.body | |
|
222 | ||
|
223 | def test_set_fork_of_repo(self): | |
|
224 | self.log_user() | |
|
225 | repo = Repository.get_by_repo_name(HG_REPO) | |
|
226 | repo2 = Repository.get_by_repo_name(GIT_REPO) | |
|
227 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), | |
|
228 | params=dict( | |
|
229 | id_fork_of=repo2.repo_id | |
|
230 | )) | |
|
231 | repo = Repository.get_by_repo_name(HG_REPO) | |
|
232 | repo2 = Repository.get_by_repo_name(GIT_REPO) | |
|
233 | self.checkSessionFlash(response, | |
|
234 | 'Marked repo %s as fork of %s' % (repo.repo_name, repo2.repo_name)) | |
|
235 | ||
|
236 | assert repo.fork == repo2 | |
|
237 | response = response.follow() | |
|
238 | # check if given repo is selected | |
|
239 | ||
|
240 | opt = """<option value="%s" selected="selected">%s</option>""" % ( | |
|
241 | repo2.repo_id, repo2.repo_name) | |
|
242 | response.mustcontain(opt) | |
|
243 | ||
|
244 | # clean session flash | |
|
245 | #response = self.app.get(url('edit_repo', repo_name=HG_REPO)) | |
|
246 | ||
|
247 | ## mark it as None | |
|
248 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), | |
|
249 | params=dict( | |
|
250 | id_fork_of=None | |
|
251 | )) | |
|
252 | repo = Repository.get_by_repo_name(HG_REPO) | |
|
253 | repo2 = Repository.get_by_repo_name(GIT_REPO) | |
|
254 | self.checkSessionFlash(response, | |
|
255 | 'Marked repo %s as fork of %s' % (repo.repo_name, "Nothing")) | |
|
256 | assert repo.fork == None | |
|
257 | ||
|
258 | def test_set_fork_of_same_repo(self): | |
|
259 | self.log_user() | |
|
260 | repo = Repository.get_by_repo_name(HG_REPO) | |
|
261 | response = self.app.put(url('repo_as_fork', repo_name=HG_REPO), | |
|
262 | params=dict( | |
|
263 | id_fork_of=repo.repo_id | |
|
264 | )) | |
|
265 | self.checkSessionFlash(response, | |
|
266 | 'An error occurred during this operation') No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now