allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From john...@apache.org
Subject [3/3] git commit: [#7207] Fixed some corner cases on default_branch_name logic and bumped version of ForgeHg
Date Tue, 01 Apr 2014 14:03:11 GMT
[#7207] Fixed some corner cases on default_branch_name logic and bumped version of ForgeHg

Signed-off-by: Cory Johns <cjohns@slashdotmedia.com>


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

Branch: refs/heads/master
Commit: f72b7fdbca7e1f22188966799911147dd19d3471
Parents: 8e075a0
Author: Cory Johns <cjohns@slashdotmedia.com>
Authored: Tue Apr 1 00:09:13 2014 +0000
Committer: Cory Johns <cjohns@slashdotmedia.com>
Committed: Tue Apr 1 00:09:13 2014 +0000

----------------------------------------------------------------------
 Allura/allura/model/repository.py               | 23 ++++++------
 .../forgegit/tests/model/test_repository.py     | 37 +++++++++++++++++++-
 requirements-sf.txt                             |  2 +-
 3 files changed, 48 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/f72b7fdb/Allura/allura/model/repository.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/repository.py b/Allura/allura/model/repository.py
index 6e63cb3..81b4cd4 100644
--- a/Allura/allura/model/repository.py
+++ b/Allura/allura/model/repository.py
@@ -664,20 +664,19 @@ class Repository(Artifact, ActivityObject):
         self.status = status
         session(self).flush(self)
 
-    def get_default_branch(self, default_name):
-        default_branch_name = getattr(
-            self, 'default_branch_name', None)
-        branch_names = []
-
+    def get_default_branch(self, default_branch_name):
+        branch_name = getattr(self, 'default_branch_name', None) or default_branch_name
+        branches = []
         if not self.is_empty():
-            branch_names = [b.name for b in self.get_branches()]
-        if default_branch_name not in branch_names:
-            if len(branch_names) == 0:
-                default_branch_name = default_name
+            branches = [b.name for b in self.get_branches()]
+
+        if branches and branch_name not in branches:
+            if default_branch_name in branches:
+                branch_name = default_branch_name
             else:
-                default_branch_name = branch_names[0]
-                self.set_default_branch(default_branch_name)
-        return default_branch_name
+                branch_name = branches[0]
+            self.set_default_branch(branch_name)
+        return branch_name
 
 
 class MergeRequest(VersionedArtifact, ActivityObject):

http://git-wip-us.apache.org/repos/asf/allura/blob/f72b7fdb/ForgeGit/forgegit/tests/model/test_repository.py
----------------------------------------------------------------------
diff --git a/ForgeGit/forgegit/tests/model/test_repository.py b/ForgeGit/forgegit/tests/model/test_repository.py
index c283798..34b726b 100644
--- a/ForgeGit/forgegit/tests/model/test_repository.py
+++ b/ForgeGit/forgegit/tests/model/test_repository.py
@@ -470,10 +470,45 @@ class TestGitRepo(unittest.TestCase, RepoImplTestBase):
             ThreadLocalORMSession.flush_all()
             assert repo2.is_empty()
 
-    def test_default_branch(self):
+    def test_default_branch_set(self):
         self.repo.default_branch_name = 'zz'
         assert_equal(self.repo.get_default_branch('master'), 'zz')
 
+    def test_default_branch_non_standard_unset(self):
+        with mock.patch.object(self.repo, 'get_branches') as gb,\
+             mock.patch.object(self.repo, 'set_default_branch') as set_db:
+            gb.return_value = [Object(name='foo')]
+            assert_equal(self.repo.get_default_branch('master'), 'foo')
+            set_db.assert_called_once_with('foo')
+
+    def test_default_branch_non_standard_invalid(self):
+        with mock.patch.object(self.repo, 'get_branches') as gb,\
+             mock.patch.object(self.repo, 'set_default_branch') as set_db:
+            self.repo.default_branch_name = 'zz'
+            gb.return_value = [Object(name='foo')]
+            assert_equal(self.repo.get_default_branch('master'), 'foo')
+            set_db.assert_called_once_with('foo')
+
+    def test_default_branch_invalid(self):
+        with mock.patch.object(self.repo, 'get_branches') as gb,\
+             mock.patch.object(self.repo, 'set_default_branch') as set_db:
+            self.repo.default_branch_name = 'zz'
+            gb.return_value = [Object(name='foo'), Object(name='master')]
+            assert_equal(self.repo.get_default_branch('master'), 'master')
+            set_db.assert_called_once_with('master')
+
+    def test_default_branch_no_clobber(self):
+        with mock.patch.object(self.repo, 'get_branches') as gb:
+            gb.return_value = []
+            self.repo.default_branch_name = 'zz'
+            assert_equal(self.repo.get_default_branch('master'), 'zz')
+
+    def test_default_branch_clobber_none(self):
+        with mock.patch.object(self.repo, 'get_branches') as gb:
+            gb.return_value = []
+            self.repo.default_branch_name = None
+            assert_equal(self.repo.get_default_branch('master'), 'master')
+
     def test_clone_url(self):
         assert_equal(
             self.repo.clone_url('rw', 'nobody'),

http://git-wip-us.apache.org/repos/asf/allura/blob/f72b7fdb/requirements-sf.txt
----------------------------------------------------------------------
diff --git a/requirements-sf.txt b/requirements-sf.txt
index 0210873..3edcfa9 100644
--- a/requirements-sf.txt
+++ b/requirements-sf.txt
@@ -4,7 +4,7 @@ akismet==0.2.0
 amqplib==0.6.1
 kombu==1.0.4
 coverage==3.5a1-20110413
-ForgeHg==0.1.21
+ForgeHg==0.1.22
 ForgePastebin==0.3.0
 GoogleCodeWikiImporter==0.5.0
 mechanize==0.2.4


Mime
View raw message