You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by tv...@apache.org on 2013/07/15 23:04:13 UTC
[17/50] [abbrv] git commit: [#5103] ticket:374 default branch option
for git
[#5103] ticket:374 default branch option for git
Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/806c3feb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/806c3feb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/806c3feb
Branch: refs/heads/tv/6355
Commit: 806c3febfa5d6ee7ae83d2505cdf6b5b8da06bab
Parents: 4358701
Author: Yuriy Arhipov <yu...@yandex.ru>
Authored: Wed Jun 19 13:33:01 2013 +0400
Committer: Tim Van Steenburgh <tv...@gmail.com>
Committed: Sun Jul 7 03:57:49 2013 +0000
----------------------------------------------------------------------
Allura/allura/lib/repository.py | 12 ++++++++
Allura/allura/model/repository.py | 1 +
.../allura/templates/repo/default_branch.html | 31 ++++++++++++++++++++
ForgeGit/forgegit/git_main.py | 18 +++++++++++-
.../tests/functional/test_controllers.py | 16 ++++++++++
ForgeGit/forgegit/tests/test_git_app.py | 7 ++++-
6 files changed, 83 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/806c3feb/Allura/allura/lib/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index 5798b21..7aa7399 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -20,6 +20,7 @@ import shutil
from urllib import quote
from pylons import tmpl_context as c, app_globals as g
+from pylons import request
from tg import expose, redirect, url
from tg.decorators import with_trailing_slash, without_trailing_slash
from bson import ObjectId
@@ -215,3 +216,14 @@ class RepoAdminController(DefaultAdminController):
@require_post()
def set_extensions(self, **post_data):
self.repo.additional_viewable_extensions = post_data['additional_viewable_extensions']
+
+ @without_trailing_slash
+ @expose('jinja:allura:templates/repo/default_branch.html')
+ def set_default_branch_name(self, branch_name=None, **kw):
+ if (request.method == 'POST') and branch_name:
+ self.repo.default_branch_name = branch_name
+ redirect(request.referer)
+ else:
+ return dict(app=self.app,
+ default_branch_name=self.app.default_branch_name)
+
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/806c3feb/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 3431e41..5492ef3 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -262,6 +262,7 @@ class Repository(Artifact, ActivityObject):
branches = FieldProperty(S.Deprecated)
repo_tags = FieldProperty(S.Deprecated)
upstream_repo = FieldProperty(dict(name=str,url=str))
+ default_branch_name = FieldProperty(str)
def __init__(self, **kw):
if 'name' in kw and 'tool' in kw:
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/806c3feb/Allura/allura/templates/repo/default_branch.html
----------------------------------------------------------------------
diff --git a/Allura/allura/templates/repo/default_branch.html b/Allura/allura/templates/repo/default_branch.html
new file mode 100644
index 0000000..c524001
--- /dev/null
+++ b/Allura/allura/templates/repo/default_branch.html
@@ -0,0 +1,31 @@
+{#-
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-#}
+
+<form action="{{c.project.url()}}admin/{{app.config.options.mount_point}}/set_default_branch_name" method="POST">
+ <label class="grid-13">Default branch name:</label>
+ <div class="grid-13">
+ <input type="text" name="branch_name" id="branch_name" {% if default_branch_name %} value="{{default_branch_name}}"{% endif %}/>
+ </div>
+ <div class="grid-13"> </div>
+ <hr>
+ <div class="grid-13"> </div>
+ <div class="grid-13">
+ <input type="submit" value="Save">
+ </div>
+</form>
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/806c3feb/ForgeGit/forgegit/git_main.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/git_main.py b/ForgeGit/forgegit/git_main.py
index 85219f8..2ba63bc 100644
--- a/ForgeGit/forgegit/git_main.py
+++ b/ForgeGit/forgegit/git_main.py
@@ -31,6 +31,7 @@ from allura import model as M
from allura.controllers.repository import RepoRootController, RefsController, CommitsController
from allura.controllers.repository import MergeRequestsController, RepoRestController
from allura.lib.repository import RepositoryApp
+from allura.app import SitemapEntry
# Local imports
from . import model as GM
@@ -50,7 +51,6 @@ class ForgeGitApp(RepositoryApp):
"""
ordinal=2
forkable=True
- default_branch_name='master'
def __init__(self, project, config):
super(ForgeGitApp, self).__init__(project, config)
@@ -64,6 +64,22 @@ class ForgeGitApp(RepositoryApp):
def repo(self):
return GM.Repository.query.get(app_config_id=self.config._id)
+ @property
+ def default_branch_name(self):
+ default_branch_name = getattr(self.repo, 'default_branch_name', 'master')
+ if not default_branch_name:
+ default_branch_name = 'master'
+ return default_branch_name
+
+ def admin_menu(self):
+ links = []
+ links.append(SitemapEntry(
+ 'Set default branch',
+ c.project.url()+'admin/'+self.config.options.mount_point+'/' + 'set_default_branch_name',
+ className='admin_modal'))
+ links += super(ForgeGitApp, self).admin_menu()
+ return links
+
def install(self, project):
'''Create repo object for this tool'''
super(ForgeGitApp, self).install(project)
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/806c3feb/ForgeGit/forgegit/tests/functional/test_controllers.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/functional/test_controllers.py b/ForgeGit/forgegit/tests/functional/test_controllers.py
index c4ac325..841d0fb 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -354,6 +354,22 @@ class TestRootController(_TestCase):
download_link = [a for a in links if a.text == 'Download Snapshot'][0]
assert_equal(download_link.get('href'), '/p/test/testgit-index/ci/master/tarball?path=/index')
+ def test_default_branch(self):
+ assert_equal(c.app.default_branch_name, 'master')
+ c.app.repo.default_branch_name = 'zz'
+ assert_equal(c.app.default_branch_name, 'zz')
+ r = self.app.get('/p/test/src-git/').follow().follow()
+ assert '<span class="scm-branch-label">zz</span>' in r
+
+ def test_set_default_branch(self):
+ r = self.app.get('/p/test/admin/src-git/set_default_branch_name')
+ assert '<input type="text" name="branch_name" id="branch_name" value="master"/>' in r
+ self.app.post('/p/test/admin/src-git/set_default_branch_name', params={'branch_name':'zz'})
+ r = self.app.get('/p/test/admin/src-git/set_default_branch_name')
+ assert '<input type="text" name="branch_name" id="branch_name" value="zz"/>' in r
+ r = self.app.get('/p/test/src-git/').follow().follow()
+ assert '<span class="scm-branch-label">zz</span>' in r
+
class TestRestController(_TestCase):
http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/806c3feb/ForgeGit/forgegit/tests/test_git_app.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/test_git_app.py b/ForgeGit/forgegit/tests/test_git_app.py
index f315600..5d745b4 100644
--- a/ForgeGit/forgegit/tests/test_git_app.py
+++ b/ForgeGit/forgegit/tests/test_git_app.py
@@ -39,7 +39,12 @@ class TestGitApp(unittest.TestCase):
ThreadLocalORMSession.close_all()
def test_admin_menu(self):
- assert_equals(len(c.app.admin_menu()), 4)
+ assert_equals(len(c.app.admin_menu()), 5)
+
+ def test_default_branch(self):
+ assert c.app.default_branch_name == 'master'
+ c.app.repo.default_branch_name = 'zz'
+ assert c.app.default_branch_name == 'zz'
def test_uninstall(self):
from allura import model as M