Rev 6: Add some tests that checking for being merged works correctly. in http://bzr.arbash-meinel.com/plugins/raf

John Arbash Meinel john at arbash-meinel.com
Wed Jan 14 21:12:21 GMT 2009


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

------------------------------------------------------------
revno: 6
revision-id: john at arbash-meinel.com-20090114211204-ziw35z3znsjadps8
parent: john at arbash-meinel.com-20090114205307-9yxb0itq7w3mr0k0
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: raf
timestamp: Wed 2009-01-14 15:12:04 -0600
message:
  Add some tests that checking for being merged works correctly.
-------------- next part --------------
=== modified file '__init__.py'
--- a/__init__.py	2009-01-14 20:46:25 +0000
+++ b/__init__.py	2009-01-14 21:12:04 +0000
@@ -73,12 +73,23 @@
                     ]
 
     def run(self, url=None, target=None, archive=None, no_check=False):
+        from bzrlib import missing
         from bzrlib.plugins.raf import raf
 
         b, wt = raf.find_branch_to_archive(url)
 
         archive_trans, archived_url = raf.get_archived_location(b, archive)
 
+        if not no_check: # Sorry about the double negative...
+            possible_trans = [archive_trans, b.bzrdir.transport]
+            target_b = raf.get_target_branch(target, possible_trans)
+            unmerged_revs, _ = missing.find_unmerged(b, target_b,
+                restrict='local', include_merges=False, backward=False)
+            if unmerged_revs:
+                raise errors.BzrCommandError('There are %d unmerged revisions'
+                    ' in\n  %s\nthat are not in\n  %s.'
+                    % (len(unmerged_revs), b, target_b))
+
 commands.register_command(cmd_archive_branch)
 
 

=== modified file 'raf.py'
--- a/raf.py	2009-01-14 20:53:07 +0000
+++ b/raf.py	2009-01-14 21:12:04 +0000
@@ -24,6 +24,7 @@
 from bzrlib import (
     branch,
     errors,
+    missing,
     transport,
     urlutils,
     workingtree,
@@ -102,3 +103,5 @@
         from bzrlib.plugins.raf import DEFAULT_TARGET_BRANCH
         target = DEFAULT_TARGET_BRANCH
     return branch.Branch.open(target, possible_transports=possible_transports)
+
+

=== modified file 'test_blackbox_raf.py'
--- a/test_blackbox_raf.py	2009-01-14 19:49:12 +0000
+++ b/test_blackbox_raf.py	2009-01-14 21:12:04 +0000
@@ -19,8 +19,40 @@
 from bzrlib import (
     tests,
     )
-
-
-class TestRAF(tests.TestCaseWithTransport):
-
-    pass
+from bzrlib.plugins import raf
+
+
+class TestArchiveBranch(tests.TestCaseWithTransport):
+
+    def setUp(self):
+        super(TestArchiveBranch, self).setUp()
+        # Set up a location for the archive
+        # and a target branch that has a revision
+        self.archive_url = self.get_url('archive')
+        self.build_tree(['archive/'])
+
+        builder = self.make_branch_builder('target')
+        builder.build_snapshot('first-rev', None, [
+            ('add', ('', 'root-id', 'directory', None))])
+        self.target_branch = builder.get_branch()
+
+        # Point the defaults for 'archive-branch' to these values, but make
+        # sure to restore the original values when the test is done
+        orig_default_target = raf.DEFAULT_TARGET_BRANCH
+        orig_default_archive = raf.DEFAULT_ARCHIVE_BASE
+        def reset_defaults():
+            raf.DEFAULT_TARGET_BRANCH = orig_default_target
+            raf.DEFAULT_ARCHIVE_BASE = orig_default_archive
+        raf.DEFAULT_ARCHIVE_BASE = self.archive_url
+        raf.DEFAULT_TARGET_BRANCH = self.target_branch.base
+
+    def test_missing_revs(self):
+        extra_bzrdir = self.target_branch.bzrdir.sprout('feature')
+        extra_tree = extra_bzrdir.open_workingtree()
+        extra_tree.commit('unmerged', rev_id='unmerged-rev')
+
+        # It should fail because there are extra revisions
+        self.run_bzr_error(['There are 1 unmerged revisions'],
+                           'archive-branch feature')
+        # Unless we tell it not to check
+        self.run_bzr('archive-branch feature --no-check')



More information about the bazaar-commits mailing list