def test_switch_thread_up_does_not_merge(self): tree = self.get_vendor_loom() self._add_patch(tree, 'thread1') rev_id = self._add_patch(tree, 'thread2') loom_tree = LoomTreeDecorator(tree) loom_tree.down_thread('vendor') out, err = self.run_bzr(['switch', 'thread2'], retcode=0) self.assertEqual('', out) self.assertEqual( "All changes applied successfully.\nMoved to thread 'thread2'.\n", err) self.assertEqual([rev_id], tree.get_parent_ids())
def test_switch_dash_b(self): # 'bzr switch -b new-thread' makes and switches to a new thread. tree = self.get_vendor_loom() self._add_patch(tree, 'thread2') LoomTreeDecorator(tree).down_thread('vendor') self.assertEqual(tree.branch.nick, 'vendor') out, err = self.run_bzr(['switch', '-b', 'thread1'], retcode=0) self.assertEqual(tree.branch.nick, 'thread1') self.assertEqual('', out) self.assertEqual('', err)
def test_sprout_nonempty_loom_bottom(self): """Sprouting always resets the loom to the top.""" source_tree = self.get_tree_with_one_commit('source') source_tree.branch.new_thread('bottom') source_tree.branch.new_thread('top') source_tree.branch._set_nick('top') source_tree.commit('phwoar', allow_pointless=True) source_tree.branch.record_loom('commit to loom') LoomTreeDecorator(source_tree).down_thread() # now sprout target_tree = source_tree.controldir.sprout('target').open_workingtree() self.assertLoomSproutedOk(source_tree, target_tree)
def test_switch_top(self): # 'bzr switch top:' switches to the top thread. tree = self.get_vendor_loom() self._add_patch(tree, 'thread1') self._add_patch(tree, 'thread2') LoomTreeDecorator(tree).down_thread('vendor') self.assertEqual(tree.branch.nick, 'vendor') out, err = self.run_bzr(['switch', 'top:'], retcode=0) self.assertEqual('', out) self.assertEqual( "All changes applied successfully.\nMoved to thread 'thread2'.\n", err)
def test_revert_loom_remove_current_thread_mid_loom(self): # given the loom Base, => mid, top, with a basis of Base, top, revert # of the loom should end up with Base, =>top, including last-revision # changes tree = self.get_tree_with_loom() tree = LoomTreeDecorator(tree) # new threads tree.branch.new_thread('base') tree.branch.new_thread('top') tree.branch._set_nick('top') # and a change to the revision history of this thread tree.tree.commit('change top', allow_pointless=True) last_rev = tree.branch.last_revision() # now record tree.branch.record_loom('change top') tree.down_thread() tree.branch.new_thread('middle', 'base') tree.up_thread() self.assertEqual('middle', tree.branch.nick) tree.branch.revert_loom() # the threads list should be restored self.assertEqual( [('base', b'empty:', [EMPTY_REVISION]), ('top', last_rev, [last_rev])], tree.branch.get_loom_state().get_threads()) self.assertEqual(last_rev, tree.branch.last_revision())
def test_push_loom_loom(self): """Pushing a loom to a loom copies the current loom state.""" source = self.get_tree_with_loom('source') source.branch.new_thread('bottom') source.branch.new_thread('top') source.branch._set_nick('bottom') source.branch.record_loom('commit to loom') target = source.controldir.sprout('target').open_branch() target._set_nick('top') # put a commit in the bottom and top of this loom bottom_rev1 = source.commit('commit bottom') source_loom_tree = LoomTreeDecorator(source) source_loom_tree.up_thread() top_rev1 = source.commit('integrate bottom changes.') source_loom_tree.down_thread() # and now another commit at the bottom bottom_rev2 = source.commit('bottom 2', allow_pointless=True) source.branch.record_loom('commit to loom again') # we now have two commits in the bottom warp, one in the top, and # all three should be pulled. We are pushing into a loom which has # a different current thread too : that should not affect us. source.branch.push(target) for rev in (bottom_rev1, bottom_rev2, top_rev1): self.assertTrue(target.repository.has_revision(rev)) # check loom threads threads = target.get_loom_state().get_threads() self.assertEqual( [('bottom', bottom_rev2, [bottom_rev2]), ('top', top_rev1, [top_rev1])], threads) # check loom tip was pulled loom_rev_ids = source.branch.loom_parents() for rev_id in loom_rev_ids: self.assertTrue(target.repository.has_revision(rev_id)) self.assertEqual(source.branch.loom_parents(), target.loom_parents())
def make_and_clone_simple_loom(self): source_tree = self.get_tree_with_one_commit('source') source_tree.branch.new_thread('bottom') source_tree.branch.new_thread('top') source_tree.branch._set_nick('top') source_tree.commit('phwoar', allow_pointless=True) source_tree.branch.record_loom('commit to loom') LoomTreeDecorator(source_tree).down_thread() # now clone from the 'default url' - transport_server rather than # vfs_server. source_branch = Branch.open(self.get_url('source')) target_tree = source_branch.controldir.sprout('target').open_workingtree() self.assertLoomSproutedOk(source_tree, target_tree)
def get_two_thread_loom(self): tree = self.get_vendor_loom() tree.branch.new_thread('above-vendor') loom_tree = LoomTreeDecorator(tree) loom_tree.up_thread() self.build_tree(['file-a']) tree.add('file-a') tree.commit('change the tree', rev_id=b'above-vendor-1') loom_tree.down_thread() return tree, loom_tree
def test_revert_thread(self): """bzr revert-loom threadname should restore the state of that thread.""" # we want a loom with > 1 threads, with a change made to a thread we are # not in, so we can revert that by name, tree = self.get_vendor_loom() tree.branch.new_thread('after-vendor') tree.branch._set_nick('after-vendor') tree.commit('after-vendor commit', allow_pointless=True) tree.branch.record_loom('save loom with vendor and after-vendor') old_threads = tree.branch.get_loom_state().get_threads() tree.commit('after-vendor commit 2', allow_pointless=True) LoomTreeDecorator(tree).down_thread() last_rev = tree.last_revision() self.assertNotEqual(NULL_REVISION, last_rev) out, err = self.run_bzr(['revert-loom', 'after-vendor']) self.assertEqual('', out) self.assertEqual("thread 'after-vendor' reverted.\n", err) self.assertEqual(last_rev, tree.last_revision()) self.assertEqual(old_threads, tree.branch.get_loom_state().get_threads())
def test_pull(self): """Integration smoke test for bzr pull loom to loom.""" tree = self.get_vendor_loom('source') tree.branch.record_loom('commit loom.') tree.controldir.sprout('target') tree.commit('change the source', allow_pointless=True) tree.branch.new_thread('foo') LoomTreeDecorator(tree).up_thread() tree.branch.record_loom('commit loom again.') os.chdir('target') try: out, err = self.run_bzr(['pull']) finally: os.chdir('..') self.assertStartsWith(out, 'Using saved parent location:') self.assertEndsWith(out, 'Now on revision 2.\n') self.assertEqual( 'All changes applied successfully.\n', err) # lower level tests check behaviours, just check show-loom as a smoke # test. out, err = self.run_bzr(['show-loom', 'target']) self.assertEqual('=>foo\n vendor\n', out) self.assertEqual('', err)
def get_loom_with_unique_thread(self): """Return a loom with a unique thread. That is: vendor:[] unique-thread:[vendor] above-vendor:[vendor] - unique-thread has work not in vendor and not in above-vendor. The returned loom is on the vendor thread. """ tree, _ = self.get_two_thread_loom() tree.branch.new_thread('unique-thread', 'vendor') loom_tree = LoomTreeDecorator(tree) loom_tree.up_thread() self.build_tree(['file-b']) tree.add('file-b') tree.commit('a unique change', rev_id=b'uniquely-yrs-1') loom_tree.down_thread() return tree, loom_tree