allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brond...@apache.org
Subject [19/50] [abbrv] git commit: [#5103] ticket:396 Set HEAD when switching default branch
Date Thu, 11 Jul 2013 21:58:39 GMT
[#5103] ticket:396 Set HEAD when switching default branch


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/19c76736
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/19c76736
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/19c76736

Branch: refs/heads/db/6277
Commit: 19c7673683bc16f87a9021088f49a94244959150
Parents: a5680c0
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Mon Jul 1 09:43:46 2013 +0000
Committer: Tim Van Steenburgh <tvansteenburgh@gmail.com>
Committed: Sun Jul 7 03:59:51 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/repository.py                       |  2 +-
 Allura/allura/model/repository.py                     | 10 ++++++++++
 ForgeGit/forgegit/model/git_repo.py                   |  7 +++++++
 .../forgegit/tests/functional/test_controllers.py     | 14 ++++++++++----
 4 files changed, 28 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19c76736/Allura/allura/lib/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/repository.py b/Allura/allura/lib/repository.py
index 7aa7399..95a3d54 100644
--- a/Allura/allura/lib/repository.py
+++ b/Allura/allura/lib/repository.py
@@ -221,7 +221,7 @@ class RepoAdminController(DefaultAdminController):
     @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
+            self.repo.set_default_branch(branch_name)
             redirect(request.referer)
         else:
             return dict(app=self.app,

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19c76736/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 5492ef3..32cea30 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -386,6 +386,16 @@ class Repository(Artifact, ActivityObject):
     @property
     def head(self):
         return self._impl.head
+    def set_default_branch(self, name):
+        return self._impl.set_default_branch(name)
+
+    def _log(self, rev, skip, limit):
+        head = self.commit(rev)
+        if head is None: return
+        for _id in self.commitlog([head._id], skip, limit):
+            ci = head.query.get(_id=_id)
+            ci.set_context(self)
+            yield ci
 
     def init_as_clone(self, source_path, source_name, source_url):
         self.upstream_repo.name = source_name

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19c76736/ForgeGit/forgegit/model/git_repo.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/model/git_repo.py b/ForgeGit/forgegit/model/git_repo.py
index 6081a55..0da371d 100644
--- a/ForgeGit/forgegit/model/git_repo.py
+++ b/ForgeGit/forgegit/model/git_repo.py
@@ -445,6 +445,13 @@ class GitImplementation(M.RepositoryImplementation):
     def tags(self):
         return [Object(name=t.name, object_id=t.commit.hexsha) for t in self._git.tags if
t.is_valid()]
 
+    def set_default_branch(self, name):
+        if not name:
+            return
+        # HEAD should point to default branch
+        self._git.git.symbolic_ref('HEAD', 'refs/heads/%s' % name)
+        self._repo.default_branch_name = name
+        session(self._repo).flush(self._repo)
 
 class _OpenedGitBlob(object):
     CHUNK_SIZE=4096

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/19c76736/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 841d0fb..6646318 100644
--- a/ForgeGit/forgegit/tests/functional/test_controllers.py
+++ b/ForgeGit/forgegit/tests/functional/test_controllers.py
@@ -21,7 +21,7 @@ import os
 import shutil
 import tempfile
 
-from nose.tools import assert_equal
+from nose.tools import assert_equal, assert_in, assert_not_in
 import tg
 import pkg_resources
 from pylons import tmpl_context as c
@@ -356,10 +356,10 @@ class TestRootController(_TestCase):
 
     def test_default_branch(self):
         assert_equal(c.app.default_branch_name, 'master')
-        c.app.repo.default_branch_name = 'zz'
+        c.app.repo.set_default_branch('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
+        c.app.repo.set_default_branch('master')
+        assert_equal(c.app.default_branch_name, 'master')
 
     def test_set_default_branch(self):
         r = self.app.get('/p/test/admin/src-git/set_default_branch_name')
@@ -369,6 +369,12 @@ class TestRootController(_TestCase):
         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
+        assert_in('<span>bad</span>', r)  # 'bad' is a file name which in zz,
but not in master
+
+        self.app.post('/p/test/admin/src-git/set_default_branch_name', params={'branch_name':'master'})
+        r = self.app.get('/p/test/src-git/').follow().follow()
+        assert_not_in('<span>bad</span>', r)
+        assert_in('<span>README</span>', r)
 
 
 class TestRestController(_TestCase):


Mime
View raw message