Rev 2: A couple tests, and the start of a helper module. in http://bzr.arbash-meinel.com/plugins/raf

John Arbash Meinel john at arbash-meinel.com
Wed Jan 14 20:02:38 GMT 2009


At http://bzr.arbash-meinel.com/plugins/raf

------------------------------------------------------------
revno: 2
revision-id: john at arbash-meinel.com-20090114200220-ts6fo1jexvlalemz
parent: john at arbash-meinel.com-20090114194912-el18nbx90xb8q89z
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: raf
timestamp: Wed 2009-01-14 14:02:20 -0600
message:
  A couple tests, and the start of a helper module.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2009-01-14 19:49:12 +0000
+++ b/__init__.py	2009-01-14 20:02:20 +0000
@@ -20,6 +20,13 @@
 feature branch that has been finished into the archived location.
 """
 
+# This is meant to be the 'trunk' branch of your repository
+DEFAULT_TARGET_BRANCH = 'bzr+ssh://?????'
+# This is meant to be the 'archive' of old branches, when a new feature branch
+# is archived, it will be renamed into this directory
+DEFAULT_ARCHIVE_BASE = 'bzr+ssh://path/to/repo/archived'
+
+
 from bzrlib import (
     commands,
     errors,
@@ -27,12 +34,11 @@
     trace,
     )
 
+# Setting a 'version_info' member allows 'bzr plugins' to display the version
+# of the plugins you have installed.
 version_info = (0, 1, 0, 'dev', 0)
 
 
-DEFAULT_TARGET_BRANCH = 'bzr+ssh://?????'
-
-
 class cmd_archive_branch(commands.Command):
     """Move an existing branch into the archived location.
 
@@ -52,14 +58,9 @@
                     ]
 
     def run(self, url=None):
-        from bzrlib import branch, workingtree
+        from bzrlib.raf import raf
 
-        if url is None:
-            wt, relpath = workingtree.WorkingTree.open_containing('.')
-            b = wt.branch
-        else:
-            wt = None
-            b = branch.Branch.open(url)
+        wt, b = raf.find_branch_and_workingtree(url)
 
 commands.register_command(cmd_archive_branch)
 

=== added file 'raf.py'
--- a/raf.py	1970-01-01 00:00:00 +0000
+++ b/raf.py	2009-01-14 20:02:20 +0000
@@ -0,0 +1,53 @@
+# Copyright (C) 2009 RAF
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Functionality provided by the RAF plugin.
+
+Most functionality should be kept in this module, rather than in the base
+__init__.py. __init__.py is loaded every time bzr is run, so you want to keep
+it as streamlined as possible.
+"""
+
+from bzrlib import (
+    branch,
+    errors,
+    workingtree,
+    )
+
+def find_branch_to_archive(url):
+    """Find the branch that we want to archive.
+
+    The URL is the one supplied by the user. It might be None, indicating that
+    we want to look at the current working directory.
+
+    :return: (branch, workingtree)
+        The branch is the branch which should be archived.
+        If workingtree is not None, then we have a checkout of another branch,
+        which means we need to update the checkout after the branch is
+        archived.
+    """
+    if url is None:
+        try:
+            wt, relpath = workingtree.WorkingTree.open_containing('.')
+            b = wt.branch
+        except errors.NoWorkingTree:
+            b = branch.Branch.open('.')
+            wt = None
+    else:
+        wt = None
+        b = branch.Branch.open(url)
+
+    return b, wt

=== modified file 'test_raf.py'
--- a/test_raf.py	2009-01-14 19:49:12 +0000
+++ b/test_raf.py	2009-01-14 20:02:20 +0000
@@ -16,11 +16,49 @@
 
 """Whitebox tests of the RAF plugin functionality."""
 
+import os
+
 from bzrlib import (
+    errors,
     tests,
     )
-
-
-class TestRAF(tests.TestCaseWithTransport):
-
-    pass
+from bzrlib.plugins.raf import (
+    raf,
+    )
+
+
+class TestFindBranchToArchive(tests.TestCaseWithTransport):
+
+    def test_find_local_working_tree(self):
+        tree = self.make_branch_and_tree('.')
+
+        b, wt = raf.find_branch_to_archive(None)
+        self.assertIsNot(None, wt)
+        self.assertEqual(tree.branch.base, b.base)
+
+
+    def test_find_local_working_tree_from_subdir(self):
+        tree = self.make_branch_and_tree('.')
+
+        # We should be able to find the containing working-tree, even if we are
+        # currently in a subdirectory
+        os.mkdir('subdir')
+        os.chdir('subdir')
+        b, wt = raf.find_branch_to_archive(None)
+        self.assertIsNot(None, wt)
+        self.assertEqual(tree.branch.base, b.base)
+
+    def test_find_just_branch(self):
+        b = self.make_branch('.')
+
+        found_b, wt = raf.find_branch_to_archive(None)
+        self.assertIs(None, wt)
+        self.assertEqual(b.base, found_b.base)
+
+        # However, if we have just a branch, we don't search for the containing
+        # 'branch'. This is because we don't want to accidentally find a
+        # containing branch that we didn't really intend to change
+        os.mkdir('subdir')
+        os.chdir('subdir')
+        self.assertRaises(errors.NotBranchError,
+                          raf.find_branch_to_archive, None)



More information about the bazaar-commits mailing list